Chapter 8 Poisson regression & analysis of curved effects
This exercise deals with modelling incidence rates using Poisson regression. Our special interest is in estimating and reporting curved effects of continuous explanatory variables on the hazard rate, i.e. the theoretical incidence rate
We analyse the testisDK
data found in the
Epi
package.
It contains the numbers of cases of testis cancer and mid-year
populations (person-years) in 1-year age groups in Denmark during
1943-96. In this analysis age and calendar time
are first treated as categorical
but finally, a penalized spline model is fitted.
8.1 Testis cancer: Data input and housekeeping
- Load the packages and the data set, and inspect its structure:
- There are nearly 5000 observations from 90 one-year age groups and 54 calendar years. To get a clearer picture of what’s going on, we do some housekeeping. The age range will be limited to 15-79 years, and age and period are both categorized into 5-year intervals – following to the time-honoured practice in epidemiology.
8.2 Some descriptive analysis
Computation and tabulation of incidence rates
- Tabulate numbers of cases and person-years, and compute the
incidence rates (per 100,000 y) in each 5 y \(\times\) 5 y cell using
stat.table()
. Take a look at the structure of the thus created object
tab <- stat.table(
index = list(Age, Per),
contents = list(
D = sum(D),
Y = sum(Y / 1000),
rate = ratio(D, Y, 10^5)
),
margins = TRUE,
data = tdk
)
str(tab)
The table is too wide to be readable as such. A graphical presentation is more informative.
- From the saved table object
tab
you can plot an age-incidence curve for each period separately, after you have checked the structure of the table, so that you know the relevant dimensions in it. There is a functionrateplot()
inEpi
that does default plotting of tables of rates (see the help page ofrateplot
)
str(tab)
par(mfrow = c(1, 1))
rateplot(
rates = tab[3, 1:nAge, 1:nPer], which = "ap", ylim = c(1, 30),
age = seq(15, 75, 5), per = seq(1943, 1993, 5),
col = heat.colors(16), ann = TRUE
)
What can you conclude about the trend in age-specific incidence rates over calendar time? What about the effect of age; is there any common pattern in the age-incidence curves across the periods?
8.3 Age and period as categorical factors
We shall first fit a Poisson regression model with log link on age and period model in the traditional way, in which both factors are treated as categorical. The model is additive on the log-rate scale. It is useful to scale the person-years to be expressed in \(10^5\) y.
- In fitting the model we utilize the
poisreg
family object found in packageEpi
.
tdk$Y <- tdk$Y / 100000
mCat <- glm(cbind(D, Y) ~ Age + Per,
family = poisreg(link = log), data = tdk )
round(ci.exp(mCat), 2)
What do the estimated rate ratios tell about the age and period effects?
- A graphical inspection of point estimates and confidence intervals can be obtained as follows. In the beginning it is useful to define shorthands for the pertinent mid-age and mid-period values of the different intervals
aMid <- seq(17.5, 77.5, by = 5)
pMid <- seq(1945, 1995, by = 5)
par(mfrow = c(1, 2))
matplot(aMid, rbind(c(1,1,1), ci.exp(mCat)[2:13, ]), type = "o", pch = 16,
log = "y", cex.lab = 1.5, cex.axis = 1.5, col= c("black", "blue", "blue"),
xlab = "Age (years)", ylab = "Rate ratio" )
matplot(pMid, rbind(c(1,1,1), ci.exp(mCat)[14:23, ]), type = "o", pch = 16,
log = "y", cex.lab = 1.5, cex.axis = 1.5, col=c("black", "blue", "blue"),
xlab = "Calendar year - 1900", ylab = "Rate ratio" )
- In the fitted model the reference category for each factor was
the first one. As age is the dominating factor, it may be more
informative to remove the intercept from the model. As a
consequence the age effects describe fitted rates at the reference
level of the period factor. For the latter one could choose the
middle period 1968-72 using
Relevel()
.
tdk$Per70 <- Relevel(tdk$Per, ref = 6)
mCat2 <- glm(cbind(D, Y) ~ -1 + Age + Per70,
family = poisreg(link = log), data = tdk )
round(ci.exp(mCat2), 2)
- Let us also plot estimates from the latter model, too.
par(mfrow = c(1, 2))
matplot(aMid, rbind(c(1,1,1), ci.exp(mCat2)[2:13, ]), type = "o", pch = 16,
log = "y", cex.lab = 1.5, cex.axis = 1.5, col=c("black", "blue", "blue"),
xlab = "Age (years)", ylab = "Rate" )
matplot(pMid, rbind(ci.exp(mCat2)[14:18, ], c(1,1,1), ci.exp(mCat2)[19:23, ]),
type = "o", pch = 16, log = "y", cex.lab = 1.5, cex.axis = 1.5,
col=c("black", "blue", "blue"),
xlab = "Calendar year - 1900", ylab = "Rate ratio" )
abline(h = 1, col = "gray")
8.4 Generalized additive model with penalized splines
It is obvious that the age effect on the log-rate scale is highly non-linear. Yet, it is less clear whether the true period effect deviates from linearity. Nevertheless, there are good reasons to try fitting smooth continuous functions for both time scales.
- As the next task we fit a generalized additive model for the
log-rate on continuous age and period applying penalized splines
with default settings of function
gam()
in packagemgcv
. In this fitting an optimal value for the penalty parameter is chosen based on an AIC-like criterion known as UBRE (‘Un-Biased Risk Estimator’)
library(mgcv)
mPen <- mgcv::gam(cbind(D, Y) ~ s(A) + s(P),
family = poisreg(link = log), data = tdk
)
summary(mPen)
The summary is quite brief, and the only estimated coefficient is the
intercept, which sets the baseline level for the log-rates, against
which the relative age effects and period effects will be contrasted.
On the rate scale the baseline level 5.53 per 100000 y is obtained by
exp(1.7096)
.
- See also the default plot for the fitted curves (solid lines) describing the age and the period effects which are interpreted as contrasts to the baseline level on the log-rate scale.
The dashed lines describe the approximate 95% confidence band for the pertinent
curve. One could get the impression that year 1968 would be some kind
of reference value for the period effect, like period 1968-72
chosen as the reference in the categorical
model previously fitted. This is not the case, however, because
gam()
by default parametrizes the spline effects such that the
reference level, at which the spline effect is nominally zero, is the
overall grand mean value of the log-rate in the data. This
corresponds to the principle of sum contrasts (contr.sum
)
for categorical explanatory factors.
From the summary you will also find that the degrees of freedom value
required for the age effect is nearly the same as the default
dimension \(k-1 = 9\) of the part of the model matrix (or basis)
initially allocated for each smooth function. (Here \(k\) refers to the
relevant argument that determines the basis dimension when specifying
a smooth term by s()
in the model formula). On the other
hand the period effect takes just about 3 df.
- It is a good idea to do some diagnostic checking of the fitted model
The four diagnostic plots are analogous to some of those used in
the context of linear models for Gaussian responses, but not all of them
may be as easy to interpret. – Pay attention to the note
given in the printed output about the value of k
.
- Let us refit the model but now with an increased
k
for age:
mPen2 <- mgcv::gam(cbind(D, Y) ~ s(A, k = 20) + s(P),
family = poisreg(link = log), data = tdk
)
summary(mPen2)
par(mfrow = c(2, 2))
gam.check(mPen2)
With this choice of k
the df value for age became about 11,
which is well below \(k-1 = 19\). Let us plot the fitted curves from
this fitting, too
There does not seem to have happened any essential changes from the previously fitted curves, so maybe 8 df could, after all, be quite enough for the age effect.
- Graphical presentation of the effects using
plot.gam()
can be improved. For instance, we may present the age effect to describe the mean incidence rates by age, averaged over the whole time span of 54 years. This is obtained by adding the estimated intercept to the estimated smooth curve for the age effect and showing the antilogarithms of the ordinates of the curve. For that purpose we need to extract the intercept and modify the labels of the \(y\)-axis accordingly. The estimated period curve can also be expressed in terms of relative indidence rates in relation to the fitted baseline rate, as determined by the model intercept.
par(mfrow = c(1, 2))
icpt <- coef(mPen2)[1] # estimated intecept
plot(mPen2,
seWithMean = TRUE, select = 1, rug = FALSE,
yaxt = "n", ylim = c(log(1), log(20)) - icpt,
xlab = "Age (y)", ylab = "Mean rate (/100000 y)"
)
axis(2, at = log(c(1, 2, 5, 10, 20)) - icpt, labels = c(1, 2, 5, 10, 20))
plot(mPen2,
seWithMean = TRUE, select = 2, rug = FALSE,
yaxt = "n", ylim = c(log(0.4), log(2)),
xlab = "Calendat year", ylab = "Relative rate"
)
axis(2, at = log(c(0.5, 0.75, 1, 1.5, 2)), labels = c(0.5, 0.75, 1, 1.5, 2))
abline(v = 1968, h = 0, lty = 3)
Homework
You could continue the analysis of these data by fitting an age-cohort
model as an alternative to the age-period model, as well as an
age-cohort-period model utilizing function apc.fit()
in
Epi
. See (http://bendixcarstensen.com/APC/) for details.