I have subset some data frames based on a three month period and named like jfm (for January to March) , fma(February to April) , mam(March to May) … until ond(October to December). I wish to run similar analysis on all of these data using several variables as regressors. Below I show how I run the analysis for one the two subset data frames using one of the pollutants as a regressor. I am interested to run the analysis for all pollutants (pm10median, pm25median, o3median and so2median) each entered into the model separately. How can I do this analysis for all data frames?
library(gamair)
library(mgcv)
data(chicago)
chicago$date<-seq(from=as.Date("1987-01-01"), to=as.Date("2000-12-31"),length=5114)
chicago$month<-as.numeric(format(chicago$date,"%m")) ## create month
jfm <- subset(chicago, month %in% c(1:3) ) ## subset data for January to March
fma <- subset(chicago, month %in% c(2:4) ) ## February to April
mam <- subset(chicago, month %in% c(3:5) ) ## March to may
jfm$trend<-seq(dim(jfm)[1]) ## cretae a trend for specific df based on dimension of the df
fma$trend<-seq(dim(fma)[1]) ## trend for df fma
## Regress each pollutant separately on death for the first subset
model1<-gam(death ~ pm10median + s(trend,k=21)+ s(tmpd,k=6) ,family=quasipoisson,na.action=na.omit,data=jfm)
model2<-gam(death ~ pm10median + s(trend,k=21)+ s(tmpd,k=6) ,family=quasipoisson,na.action=na.omit,data=fma)