Re: [R] te( ) interactions and AIC model selection with GAM
- About the visualization, my question is more about interpretation. In the case of : model_name - gam ( bm ~ t + te (t_year, temp_W, temp_sept, k = 5, bs = c( “cc”,”cr”,”cr”)), data = data) * a)* vis.gam (model_name , view= c(“t_year”, “temp_W”)) *b)* vis.gam (model_name , view= c(“t_year”, “temp_sept”)) I imagine that what we see in a) is the effect on t_year by temp_W but this effect is also affected by temp-sept right? In other words, is what we see the effect of temp_W on t_year considering the other element of the model which is temp-sept? - About AIC model selection, my question is more focus on whether it is necessary to use the same the same type of smoother ( e.g te) and the same dimension of the basis (k) for different model comparison...that is, if I have a complex model in my list of models that I want to compare like: gam ( bm ~ t + te (t_year, temp_W, temp_sept, k = 5, bs = c( “cc”,”cr”,”cr”)), data = data) should I always use as type smoother te () instead of using s ( ) and always fix the k as k = 5?? Here the maximum k I can put is k = 5. for example, let's say I have another simpler model in my list of models I want to compare in which I want to check the relationship between bm and t. Can I write it like /gam (bm ~ s(t, k = 13, bs = “cr”), data = data) /? Or I have to write like/ gam (bm ~ te (t, k = 5, bs = “cr”), data = data)/ to do the comparison in the same conditions for all the models? Thank you very much for your response Simon, Best regards, Ricardo -- View this message in context: http://r.789695.n4.nabble.com/te-interactions-and-AIC-model-selection-with-GAM-tp4638368p4638922.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] te( ) interactions and AIC model selection with GAM
- About the first question, I was not sure about what was the proper model ( a) or b) ) because I saw this at the end of the help for te --- ?te : n - 500 v - runif(n);w-runif(n);u-runif(n) f - test2(u,v,w) y - f + rnorm(n)*0.2 # tensor product of 2D thin plate regression spline and 1D cr spline b - gam(y~te(v,w,u,k=c(30,5),d=c(2,1),bs=c(tp,cr))) op - par(mfrow=c(2,2)) vis.gam(b,cond=list(u=0),color=heat,zlim=c(-0.2,3.5)) vis.gam(b,cond=list(u=.33),color=heat,zlim=c(-0.2,3.5)) vis.gam(b,cond=list(u=.67),color=heat,zlim=c(-0.2,3.5)) vis.gam(b,cond=list(u=1),color=heat,zlim=c(-0.2,3.5)) par(op) But maybe is because of the *tp* basis, and I use a *cc* one. Could be due to this? - About the visualization, my question is more about interpretation. In the case of : model_name - gam ( bm ~ t + te (t_year, temp_W, temp_sept, k = 5, bs = c( “cc”,”cr”,”cr”)), data = data) * a)* vis.gam (model_name , view= c(“t_year”, “temp_W”)) *b) *vis.gam (model_name , view= c(“t_year”, “temp_sept”)) I imagine that what we see in a) is the effect on t_year by temp_W but this effect is also affected by temp-sept right? In other words, is what we see the effect of temp_W on t_year considering the other element of the model which is temp-sept? - About AIC model selection, my question is more focus on whether it is necessary to use the same type of smoother ( e.g te) and the same dimension of the basis (k) for different model comparison...that is, if I have a complex model in my list of models that I want to compare like: gam ( bm ~ t + te (t_year, temp_W, temp_sept, k = 5, bs = c( “cc”,”cr”,”cr”)), data = data) should I always use as type smoother te () instead of using s ( ) and always fix the k as k = 5?? Here the maximum k I can put is k = 5. for example, let's say I have another simpler model in my list of models I want to compare in which I want to check the relationship between bm and t. Can I write it like /gam (bm ~ s(t, k = 13, bs = “cr”), data = data)/ ? Or I have to write like /gam (bm ~ te (t, k = 5, bs = “cr”), data = data) /to do the comparison in the same conditions for all the models? Thank you very much for your response Simon, Best regards, Ricardo -- View this message in context: http://r.789695.n4.nabble.com/te-interactions-and-AIC-model-selection-with-GAM-tp4638368p4638965.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] how to calculate seasonal mean for temperatures
Here is my approximation: # Creation of the temporal variables DF$year - as.numeric(format(DF$date, format = %Y)) DF$month - as.numeric(format(DF$date, format = %m)) # For years with data from 2006 to 2008 DF_type1 - DF [ - which (year == 2006 month ==1 | year == 2006 month == 2 | year == 2008 month == 12), ] # For years with data from 2007 to 2011 DF_type2 - DF [ - which (year == 2007 month ==1 | year == 2007 month == 2 | year == 2011 month == 12), ] # Including the Season as a factor DF$season - factor ( with ( ifelse (( month == 1 | nonth == 2 | month == 3 ), Win, ifelse ((month == 4 | nonth == 5 | month == 6 ) , Spr, ifelse ((month == 6 | nonth == 7 | month == 8 ) , Sum, Aut) # To get the mean per year and season library (plyr) ddply ( DF, . (year, season), summarize, mean_season = mean (data)) -- View this message in context: http://r.789695.n4.nabble.com/how-to-calculate-seasonal-mean-for-temperatures-tp4638639p4638649.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] how to calculate seasonal mean for temperatures
You're totally right Jeff. My mistake! to use with, we write it like this: DF$season - factor ( with ( *DF*, ifelse (( month == 12 | nonth == 1 | month == 2 ), Win, ifelse ((month == 3 | nonth == 4 | month == 5 ) , Spr, ifelse ((month == 6 | nonth == 7 | month == 8 ) , Sum, Aut) I'm glad it was useful for you, Regards, Ricardo -- View this message in context: http://r.789695.n4.nabble.com/how-to-calculate-seasonal-mean-for-temperatures-tp4638639p4638694.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] as.date: do not know how to convert 'mydata[1]' to class Date
For me it owrks when i write it like: as.Date(paste(mydata$Delivery.Date), %m/%d/%Y) Hope it works, Regards, Ricardo -- View this message in context: http://r.789695.n4.nabble.com/as-date-do-not-know-how-to-convert-mydata-1-to-class-Date-tp4638691p4638696.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
[R] te( ) interactions and AIC model selection with GAM
Hello R users, I'm working with a time-series of several years and to analyze it, I’m using GAM smoothers from the package mgcv. I’m constructing models where zooplankton biomass (bm) is the dependent variable and the continuous explanatory variables are: -time in Julian days (t), to creat a long-term linear trend -Julian days of the year (t_year) to create an annual cycle - Mean temperature of Winter (temp_W), Temperature of September (temp_sept) or Chla. Questions: 1) To introduce a tensor product modifying the annual cycle in my model, I tried 2 different approaches: - a) gam ( bm ~ t + te (t_year, temp_W, temp_sept, k = c( 5,30), d= ( 1,2), bs = c( “cc”,”cr”)), data = data) -b) gam ( bm ~ t + te (t_year, temp_W, temp_sept, k = 5, bs = c( “cc”,”cr”,”cr”)), data = data) Here is my problem: when I’m using just 2 variables (e.g., t_year and temp_W) for the tensor product, I can understand pretty well how the interpolation works and visualize it with vis.gam() as a 3d plot or a contour one. But with 3 variables is difficult to me to understand how it works. Besides, I don’t which one is the proper way to construct it, a) or b). Finally, when I plot a) or b) as vis.gam (model_name , view= c(“t_year”, “temp_W”)), How should I interpret the plot? The effect of temp_W on the annual cycle after considering already the effect of temp_sept or just the individual effect of Temp_W on the annual cycle? 2) I’m trying to do a model selection using AIC criteria. I have several questions about it: - Should I use always the same type of smoothing basis (bs), the same type of smoother ( e.g te) and the same dimension of the basis (k)? Example: Option 1: a) mod1 - gam (bm ~ t, data = data) b) mod2 - gam (bm ~ te (t, k = 5, bs = “cr”), data = data) c) mod3 - gam (bm ~ te (t_year, k = 5, bs = “cc”), data = data) d) mod4 - gam (bm ~ te (t_year, temp_W, k = 5, bs = c(“cc”,”cr”)), data = data) e) mod5 - gam (bm ~ te (t_year, temp_W, temp_sept, k = 5, bs = c(“cc”,”cr”,”cr”)), data = data). Here the limitation for k = 5, is due to mod5, I don’t use s () because in mod4 and mod5 te () is used and finally, I always use “cr” and “cc”. Option 2: a) mod1 - gam (bm ~ t, data = data) b) mod2 - gam (bm ~ s (t, k = 13, bs = “cr”), data = data) c) mod3 - gam (bm ~ s (t_year, k = 13, bs = “cc”), data = data) d) mod4 - gam (bm ~ te (t_year, temp_W, k = 11, bs = c(“cc”,”cr”)), data = data) e) mod5 - gam (bm ~ te (t_year, temp_W, temp_sept, k = 5, bs = c(“cc”,”cr”,”cr”)), data = data). I can get lower AIC for each of the models with Option 2, but are they comparable when I use AIC criteria? Is it therefore the proper way to do it as in Option 1? AIC (mod1, mod2, mod3, mod4, mod5). Thank you in advance, Best regards, Ricardo González-Gil -- View this message in context: http://r.789695.n4.nabble.com/te-interactions-and-AIC-model-selection-with-GAM-tp4638368.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.