Want to make an exposure-reaction curve and use this code
> model<-gam(death.total~s(pm25lag01,k=4,fx=T)+ns(tmean,df=3)+ns(rhum,df=3)+ns(time,df=28)
+ns(pmean,df=3)+as.factor(dow),data=fxdeath,family=quasipoisson)
But when I run it, it shows this
Error in as.vector(x, mode) :
cannot coerce type 'closure' to vector of type 'any'
Also please have a chance to help see why, how to modify better point
The complete code looks like this
library("splines")
library('lubridate')
library('ggplot2')
library('plyr')
library('tsModel')
library(dlnm)
library(splines)
library(mgcv)
setwd("F:/time series/Rfile")
fxdeath0<-read.csv("FZ.csv", header=TRUE, sep=',')
fxdeath=mutate(fxdeath0,t=1:length(date),
dow=wday(date),
pm25lag01=runMean(pm25,0:1), #########定义Lag变量#######
pm25lag02=runMean(pm25,0:2), #########定义Lag变量#######
pm25lag03=runMean(pm25,0:3),
pm25lag04=runMean(pm25,0:4),
pm25lag05=runMean(pm25,0:5),
pm25lag06=runMean(pm25,0:6),
pm25lag07=runMean(pm25,0:7))
model<-gam(death.total~s(pm25lag01,k=4,fx=T)+ns(tmean,df=3)+ns(rhum,df=3)+ns(time,df=28)+ns(pmean,df=3)+as.factor(dow),data=fxdeath,family=quasipoisson)
plot(model,main = '呼吸系统死亡',xlab = 'PM2.5', cex.axis=1.5,cex.lab=1.5,cex.main=1.5,ylab = 'Log RR',xlim=c(0,70))