# Example 1. See crosspred and plot.crosspred for other examples
### simple DLM
### space of predictor: linear effect 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
basis.pm <- crossbasis(chicagoNMMAPS$pm10, vartype="lin", lagtype="poly",
lagdegree=4, cen=FALSE, maxlag=15)
basis.temp <- crossbasis(chicagoNMMAPS$temp, vardf=5, lagtype="strata",
lagknots=1, cenvalue=21, maxlag=3)
summary(basis.pm)
summary(basis.temp)
# RUN THE MODEL AND GET THE PREDICTION FOR PM10
library(splines)
model <- glm(death ~ basis.pm + basis.temp + ns(time, 7*14) + dow,
family=quasipoisson(), chicagoNMMAPS)
pred.pm <- crosspred(basis.pm, model, at=0:20, cumul=TRUE)
# PLOT THE LINEAR EFFECT OF PM10 ALONG LAGS
plot(pred.pm, "slices", var=10, col=3, ylab="RR", ci.arg=list(density=15,lwd=2),
main="Effect of a 10-unit increase in PM10 along lags")
plot(pred.pm, "slices", var=10, cumul=TRUE, ylab="Cumulative RR",
main="Cumulative effect of a 10-unit increase in PM10 along lags")
# GET THE FIGURES FOR THE OVERALL EFFECT, WITH CI
pred.pm$allRRfit["10"]
cbind(pred.pm$allRRlow, pred.pm$allRRhigh)["10",]
### See the vignette 'dlnmOverview' for a detailed explanation of this exampleRun the code above in your browser using DataLab