我有一些基於三個月的時間段的數據框,名字如jfm(1月至3月),fma(2月至4月),mam(3月至5月)...直到ond(10月至十二月)。我希望使用幾個變量作爲迴歸因子對所有這些數據進行類似的分析。下面我將展示如何使用其中一種污染物作爲迴歸因子對兩個子集數據幀中的一個進行分析。我有興趣對所有分別進入模型的污染物(pm10median,pm25median,o3median和so2median)進行分析。我怎樣才能對所有數據幀進行這種分析?對幾個數據幀的迴歸
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)
你不必子集,則可以通過JFM,FMA,MAM tapply使用,保理,直到OND ... –
@AdityaSihag例子嗎? :) –