When running the gam model using the mgcv package, I found a strange error message that I cannot understand. The error message was "Error in model.frame.default (formula = death ~ pm10 + Lag (residue1, 1) +: variable length is different (found for" Lag (residue1, 1) "). The number of observations used in model1 exactly the same as the length of the residual deviation, so I think this error is not related to the difference in the size or length of the data.
I found a pretty related error message on the website here , but this post did not receive an adequate response, so my problem does not help me
Reproducible example and data:
library(quantmod) library(mgcv) require(dlnm) df <- chicagoNMMAPS df1 <- df[,c("date","dow","death","temp","pm10")] df1$trend<-seq(dim(df1)[1])
Run model
model1<-gam(death ~ pm10 + s(trend,k=14*7)+ s(temp,k=5), data=df1, na.action=na.omit, family=poisson)
Get rejection balances
resid1 <- residuals(model1,type="deviance")
Add one day backlog from model 1
model1_1 <- update(model1,.~.+ Lag(resid1,1), na.action=na.omit) model1_2<-gam(death ~ pm10 + s(trend,k=14*7)+ s(temp,k=5) + Lag(resid1,1), data=df1, na.action=na.omit, family=poisson)
Both of these models issued the same error message.