# Example 3. See crossbasis and crosspred for other examples
# load and prepare the dataset
initDB()
data <- readCity("chic", collapseAge=TRUE)
data$temp <- (data$tmpd-32)*5/9
data$pm10 <- with(data, pm10tmean+pm10mtrend)
### DLNM for the effect of temperature on mortality up to 30 days of lag
### space of predictor: 5df cubic spline for temperature
### space of predictor: linear effect for PM10
### lag function: 5df natural cubic spline for temperature
### lag function: single strata at lag 0-1 for PM10
basis.pm <- crossbasis(data$pm10,vartype="lin", lagtype="strata",
cen=FALSE, maxlag=1)
basis.temp <- crossbasis(data$temp, vartype="bs", vardf=5, lagdf=5,
cenvalue=21, maxlag=30)
summary(basis.pm)
summary(basis.temp)
model <- glm(death ~ basis.pm + basis.temp, family=quasipoisson(), data)
pred.temp <- crosspred(basis.temp, model, at=-26:33)
crossplot(pred.temp, label="Temperature",
title="3D graph of temperature effect")
crossplot(pred.temp, "contour", label="Temperature",
title="Contour graph of temperature effect")
crossplot(pred.temp, "overall", label="Temperature",
title="Overall effect of temperature over 30 days of lag")
crossplot(pred.temp, "slices", var=c(-20,0,27,33),
lag=c(0,5,15,28), label="Temperature")
### See the vignette 'dlnmOverview' for a detailed explanation of this example
Run the code above in your browser using DataLab