### simple DLM
### space of predictor: linear relationship for PM10
### space of predictor: 5df natural cubic spline for temperature
### lag function: 4th degree polynomial for PM10 up to lag15
### lag function: strata intervals at lag 0 and 1-3 for temperature
# CREATE THE CROSS-BASIS FOR EACH PREDICTOR AND CHECK WITH SUMMARY
cb1.pm <- crossbasis(chicagoNMMAPS$pm10, lag=15, argvar=list(type="lin",cen=0),
arglag=list(type="poly",degree=4))
cb1.temp <- crossbasis(chicagoNMMAPS$temp, lag=3, argvar=list(df=5,cen=21),
arglag=list(type="strata",knots=1))
summary(cb1.pm)
summary(cb1.temp)
# RUN THE MODEL AND GET THE PREDICTION FOR PM10
library(splines)
model1 <- glm(death ~ cb1.pm + cb1.temp + ns(time, 7*14) + dow,
family=quasipoisson(), chicagoNMMAPS)
pred1.pm <- crosspred(cb1.pm, model1, at=0:20, bylag=0.2, cumul=TRUE)
# PLOT THE LINEAR ASSOCIATION OF PM10 ALONG LAGS
plot(pred1.pm, "slices", var=10, col=3, ylab="RR", ci.arg=list(density=15,lwd=2),
main="Effects of a 10-unit increase in PM10 along lags")
plot(pred1.pm, "slices", var=10, cumul=TRUE, ylab="Cumulative RR",
main="Cumulative effects of a 10-unit increase in PM10 along lags")
# GET THE FIGURES FOR THE OVERALL EFFECTS, WITH CI
pred1.pm$allRRfit["10"]
cbind(pred1.pm$allRRlow, pred1.pm$allRRhigh)["10",]
### See the vignette 'dlnmOverview' for a detailed explanation of this example
Run the code above in your browser using DataLab