# Example 2. See crossbasis and crossplot for other examples
# load and prepare the dataset
initDB()
data <- readCity("chic", collapseAge=TRUE)
data$temp <- (data$tmpd-32)*5/9
data$o3 <- with(data, o3mean+o3trend)
### DLM with threshold for the effect of O3 on mortality up to 5 days of lag
### space of predictor: linear effect above 40 microgr/m3 for O3
### space of predictor: linear effects below 10C and above 25C for temperature
### lag function: integer lag parameterization (unconstrained) for O3
### lag function: strata at lag 0-1, 2-6 and 7-15 for temperature
basis.o3 <- crossbasis(data$o3, vartype="hthr", varknots=40,
lagtype="integer", maxlag=5)
basis.temp <- crossbasis(data$temp, vartype="thr", varknots=c(10,25),
lagtype="strata", lagknots=c(2,7), maxlag=15)
summary(basis.o3)
summary(basis.temp)
model <- glm(death ~ basis.o3 + basis.temp, family=quasipoisson(), data)
pred.o3 <- crosspred(basis.o3, model, at=0:65)
crossplot(pred.o3, "slices", var=50,
title="Effect of a 10-unit increase in ozone along lags")
# overall effect for a 10-unit increase in ozone over 15 days of lag, with CI
pred.o3$allRRfit["50"]
cbind(pred.o3$allRRlow, pred.o3$allRRhigh)["50",]
crossplot(pred.o3, title="3D graph of ozone effect")
crossplot(pred.o3, label="Ozone", title="3D graph of ozone effect")
Run the code above in your browser using DataLab