5.2 Communal covariates
Communal (external) covariates are covariates that vary in time outside any individual, and is common to all individuals at each specific time. In econometric literature, such a variable is often called . This could be viewed upon as a special case of a time-varying covariate, but without the danger of reversed causality that was discussed above.
For some 19th century parishes in southern Sweden, yearly time series of food prices are available. In this example we use deviation from the log trend in annual rye prices, shown in Figure 5.2.
## Loading required package: survival
FIGURE 5.2: Log rye price deviations from trend, 19th century southern Sweden.
The idea behind this choice of transformation is to focus on deviations
from the “normal” as a proxy for short-term variation in economic
stress. We illustrate the idea with a subset of the built-in data set scania, and we show the information for individual No. 1.
library(eha)
scand <- scania[, c("id", "enter", "exit", "event", "birthdate", "sex", "ses")]
scand[scand$id == 1, ]## id enter exit event birthdate sex ses
## 29 1 50 59.242 1 1781.454 male lower
Now, to put on the food prices as a time-varying covariate, use the function
make.communal. We show what happens to individual No. 1.
## enter exit event birthdate id sex ses foodprices
## 1 50.000 50.296 0 1781.454 1 male lower 0.126
## 2 50.296 51.296 0 1781.454 1 male lower 0.423
## 3 51.296 52.296 0 1781.454 1 male lower -0.019
## 4 52.296 53.296 0 1781.454 1 male lower -0.156
## 5 53.296 54.296 0 1781.454 1 male lower -0.177
## 6 54.296 55.296 0 1781.454 1 male lower -0.085
## 7 55.296 56.296 0 1781.454 1 male lower -0.007
## 8 56.296 57.296 0 1781.454 1 male lower 0.104
## 9 57.296 58.296 0 1781.454 1 male lower 0.118
## 10 58.296 59.242 1 1781.454 1 male lower -0.197
A new variable, foodprices is added, and each individual’s duration
is split up in one year long intervals (except the first and last). This is
the way of treating foodprices as a time-varying covariate.
fit <- coxph(Surv(enter, exit, event) ~ ses + sex + foodprices,
data = scand)
round(summary(fit)$coefficients, 3)## coef exp(coef) se(coef) z Pr(>|z|)
## seslower -0.030 0.970 0.075 -0.404 0.686
## sexfemale 0.041 1.042 0.061 0.674 0.500
## foodprices 0.321 1.379 0.182 1.769 0.077
Socio-economic status and sex do not matter much, but food prices do; the effect is almost significant at the 5 per cent level. \(\Box\)