# 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, o3tmean+o3mtrend)
### DLM with threshold for the effect of O3 on mortality up to 5 days of lag
### space of predictor: linear effect above 40.3 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 intervals at lag 0-1, 2-6 and 7-15 for temperature
basis.o3 <- crossbasis(data$o3, vartype="hthr", varknots=40.3,
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=c(0:65,40.3,50.3))
crossplot(pred.o3, "slices", var=50.3,
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.3"]
cbind(pred.o3$allRRlow, pred.o3$allRRhigh)["50.3",]
crossplot(pred.o3, label="Ozone", title="3D graph of ozone effect")
crossplot(pred.o3, "contour", label="Ozone",
title="Contour graph of ozone effect")
### See the vignette 'dlnmOverview' for a detailed explanation of this example
Run the code above in your browser using DataLab