# Example 3. See crossbasis and crosspred for other examples
### complex DLNM
### space of predictor: 5df quadratic spline for temperature
### space of predictor: linear effect for PM10
### lag function: 5df natural cubic spline for temperature up to lag30
### lag function: single strata at lag 0-1 for PM10
# CREATE THE CROSS-BASIS FOR EACH PREDICTOR AND CHECK WITH SUMMARY
basis.pm <- crossbasis(chicagoNMMAPS$pm10,vartype="lin", lagtype="strata",
cen=FALSE, maxlag=1)
basis.temp <- crossbasis(chicagoNMMAPS$temp, vartype="bs", vardf=5, vardegree=2,
lagdf=5, cenvalue=21, maxlag=30)
summary(basis.pm)
summary(basis.temp)
# RUN THE MODEL AND GET THE PREDICTION FOR TEMPERATURE
library(splines)
model <- glm(death ~ basis.pm + basis.temp + ns(time, 7*14) + dow,
family=quasipoisson(), chicagoNMMAPS)
pred.temp <- crosspred(basis.temp, model, by=1)
# 3-D AND CONTOUR PLOTS
plot(pred.temp, xlab="Temperature", col="red", zlab="RR", shade=0.6,
main="3D graph of temperature effect")
plot(pred.temp, "contour", xlab="Temperature", key.title=title("RR"),
plot.title=title("Contour plot",xlab="Temperature",ylab="Lag"))
# MULTIPLE SLICES
plot(pred.temp, "slices", var=-20, ci="n", col=1, ylim=c(0.95,1.15), lwd=1.5,
main="Lag-specific effects at different temperature, ref. 21C")
for(i in 1:3) lines(pred.temp, "slices", var=c(0,27,33)[i], col=i+1, lwd=1.5)
legend("topright",paste("Temperature =",c(-20,0,27,33)), col=1:4, lwd=1.5)
plot(pred.temp, "slices", var=c(-20,0,27,33), lag=c(0,5,15,28), col=4,
ci.arg=list(density=40,col=grey(0.7)))
### See the vignette 'dlnmOverview' for a detailed explanation of this exampleRun the code above in your browser using DataLab