Skip to contents

Two choices must be made before running cdd(): which extrapolant to use (order) and how many pre-shock surveys to use (H). This article explains the trade-off, shows how cdd_bandwidth() scores each combination by its estimated mean squared error, and shows how forward cross-validation with cdd_cv() checks the choice against held-out pre-shock surveys.

library(cohortDD)
library(ggplot2)
data(gss_culture)

ctl <- c("factor(race)", "factor(sex)", "educ")

The choice exists only when there are several pre-shock surveys. The George Floyd example of the replication article has one, so this article uses the 1992-93 shock in the General Social Survey, outcome homosex, level 1 (“always wrong”).

The trade-off

The error of the estimate has a bias part and a variance part, and the two choices move them in opposite directions.

  • A larger H averages over more pre-shock surveys, which lowers the variance. It also reaches further back in time, where the cohort trend may differ from its value at the target, which raises the bias.
  • The kernel mean has a small variance and is biased by the slope of the cohort trend. The local-linear fit removes the slope bias and is biased only by curvature, and it has a larger variance.

When the cohort trend is close to flat, the kernel mean is the better estimator because its slope bias is small and its variance is low. When the cohort trend has a clear slope, the local-linear fit is better. The mean squared error (MSE), the squared bias plus the variance, puts the two on one scale.

Estimated mean squared error

The MSE is unknown because the bias depends on the unknown cohort trend. cdd_bandwidth() replaces the bias by an estimate built from quantities introduced in The estimator and its inference.

For the local-linear fit the bias is at most the curvature bound M times the bias factor bb, so its estimated MSE is the square of that bound plus the squared standard error.

For the kernel mean the leading bias is the slope of the cohort trend times the mean distance ubar of the window from the target. Its estimated MSE is the square of that slope bias plus the curvature bound, plus the squared standard error.

The slope is a pilot estimate. It is the slope, at the exposed survey, of a quadratic in survey year fitted to all pre-shock surveys in the age band. The same quadratic supplies the rule-of-thumb curvature used for M when M = NULL. The pilot values do not depend on H, so the comparison across windows is driven by the bias factor, the mean distance, and the standard error. The derivations are in the article that accompanies the package.

Running cdd_bandwidth()

The function runs cdd() for every H in grid and both extrapolants, and averages the estimated MSE over the target ages. The grid cannot exceed the number of pre-shock surveys in the data. In the running example the grid stops at six surveys, which reach back to 1985.

bw <- cdd_bandwidth(gss_culture, "homosex", onset = 1992, wave = 1993,
                    grid = 2:6, orders = c(0, 1),
                    ages = seq(25, 65, by = 5), b = 5, levels = 1, controls = ctl)
bw
#> Estimated mean squared error by number of pre-shock surveys H (averaged over ages; column `risk`)
#>   local-linear fit (order 1): worst-case curvature bias (M B)^2 + variance
#>   kernel mean (order 0): (|slope| |ubar| + M B)^2 + variance; slope = slope at the target of a quadratic fitted to the pre-shock series
#>  H order level     bias2      var     risk
#>  2     0     1 5.572e-04 0.002090 0.002647
#>  3     0     1 7.646e-04 0.001902 0.002667
#>  4     0     1 1.003e-03 0.001809 0.002812
#>  5     0     1 1.406e-03 0.001720 0.003126
#>  6     0     1 1.935e-03 0.001663 0.003598
#>  2     1     1 1.295e-04 0.015535 0.015664
#>  3     1     1 8.745e-05 0.006790 0.006877
#>  4     1     1 1.132e-04 0.004613 0.004727
#>  5     1     1 1.445e-04 0.003380 0.003524
#>  6     1     1 2.245e-04 0.002740 0.002965
#> 
#> Selected:
#>  H order level     bias2     var     risk  best
#>  2     0     1 0.0005572 0.00209 0.002647  TRUE
#>  6     1     1 0.0002245 0.00274 0.002965 FALSE

The first table has one row per window and extrapolant. The column order is 0 for the kernel mean and 1 for the local-linear fit, bias2 is the squared estimated bias, var is the squared standard error, and risk is their sum, the estimated MSE. All three are averaged over the target ages.

The second table, also stored as bw$selected, gives the window with the smallest estimated MSE for each extrapolant. The row with best = TRUE is the extrapolant whose minimized estimated MSE is smaller.

bw$selected
#>   H order level    bias2     var    risk  best
#> 1 2     0     1 0.000557 0.00209 0.00265  TRUE
#> 2 6     1     1 0.000224 0.00274 0.00296 FALSE

Here the estimated MSE of the kernel mean is smallest at H = 2, that of the local-linear fit is smallest at H = 6, and the smaller of the two belongs to the kernel mean.

plot_bandwidth() draws the first table.

plot_bandwidth(bw, level = "1") +
  labs(x = "Number of pre-shock surveys H", y = "Root estimated MSE")

Root estimated mean squared error against the number of pre-shock surveys for the kernel mean and the local-linear fit.

Each line is one extrapolant, the vertical axis is the square root of the estimated MSE, and the open circle marks the minimizing window of each line. The usual shape is visible. For the local-linear fit the estimated MSE is high at small H, where a line through two or three survey means is noisy, and it turns up again at large H, where the bias factor grows. For the kernel mean the variance is small at every H, and the estimated MSE rises with H because a longer window lies further from the target on average.

How to read the result

The selection is a guide and not a rule that must be followed mechanically. Three points help in using it.

  1. The ranking of the two extrapolants depends on the pilot slope. If the pre-shock trend is flat, the kernel mean is selected. If one has substantive reasons to expect a sloping cohort trend, the local-linear fit is the safer choice even when its estimated MSE is somewhat larger, because its bias bound does not depend on the slope.
  2. A flat stretch of the curve means that neighbouring windows are about equally good. Prefer a window in the flat stretch over one at the edge of the grid.
  3. Report the estimate under both extrapolants at their selected windows. Agreement between them is evidence that the choice does not drive the conclusion.

The estimates under the two selected combinations can be compared directly.

ages <- seq(25, 65, by = 10)
f_mean <- cdd(gss_culture, "homosex", onset = 1992, wave = 1993, H = h0, b = 5,
              order = 0, ages = ages, levels = 1, controls = ctl)
f_lin  <- cdd(gss_culture, "homosex", onset = 1992, wave = 1993, H = h1, b = 5,
              order = 1, ages = ages, levels = 1, controls = ctl)

data.frame(age = ages,
           kernel_mean = f_mean$ate, se_mean = f_mean$se,
           local_linear = f_lin$ate, se_linear = f_lin$se)
#>   age kernel_mean se_mean local_linear se_linear
#> 1  25     -0.1194  0.0462      -0.1259    0.0528
#> 2  35     -0.0616  0.0404      -0.0772    0.0467
#> 3  45     -0.1409  0.0398      -0.1701    0.0474
#> 4  55     -0.1321  0.0473      -0.1321    0.0536
#> 5  65     -0.0575  0.0575      -0.0191    0.0625

Results by age

The element bw$risk holds the components at each target age before averaging, which shows whether the selection is the same across the age range.

by_age <- subset(bw$risk, age %in% c(25, 45, 65) & H %in% c(3, 5),
                 select = c(age, H, order, bias2, var, risk))
by_age[order(by_age$age, by_age$order, by_age$H), ]
#>    age H order    bias2     var    risk
#> 19  25 3     0 4.56e-05 0.00195 0.00199
#> 55  25 5     0 1.29e-04 0.00173 0.00186
#> 28  25 3     1 1.97e-04 0.00674 0.00693
#> 64  25 5     1 3.14e-04 0.00346 0.00378
#> 23  45 3     0 1.31e-04 0.00143 0.00156
#> 59  45 5     0 2.25e-04 0.00133 0.00155
#> 32  45 3     1 1.92e-06 0.00632 0.00632
#> 68  45 5     1 3.11e-06 0.00284 0.00285
#> 27  65 3     0 1.76e-04 0.00301 0.00318
#> 63  65 5     0 3.32e-04 0.00278 0.00311
#> 36  65 3     1 4.50e-05 0.00802 0.00807
#> 72  65 5     1 7.77e-05 0.00463 0.00471

Setting the curvature bound

With M = NULL the curvature is the rule-of-thumb value at each age. Passing a number fixes the bound for all ages. A larger M penalizes long windows more heavily and moves the selected H down.

bw_M <- cdd_bandwidth(gss_culture, "homosex", onset = 1992, wave = 1993,
                      grid = 2:6, M = 0.005,
                      ages = seq(25, 65, by = 5), b = 5, levels = 1, controls = ctl)
bw_M$selected
#>   H order level   bias2     var    risk  best
#> 1 2     0     1 0.00119 0.00209 0.00328  TRUE
#> 2 4     1     1 0.00498 0.00461 0.00959 FALSE

Forward cross-validation

The estimated MSE relies on pilot values for the slope and the curvature. Forward cross-validation checks the choice of H without them, by doing on the pre-shock surveys what the design does at the shock.

For each candidate H and each pre-shock survey that has at least H surveys before it, cdd_cv() treats that survey as if it were an exposed survey, extrapolates to it from the H surveys that precede it, and records the squared difference between the observed mean and the extrapolation. No shock occurred at these dates, so the difference is extrapolation error plus sampling noise. The criterion is the average of the squared differences.

cv1 <- cdd_cv(gss_culture, "homosex", onset = 1992, grid = 2:5, type = "forward",
              order = 1, ages = seq(25, 65, by = 5), b = 5, levels = 1, controls = ctl)
cv0 <- cdd_cv(gss_culture, "homosex", onset = 1992, grid = 2:5, type = "forward",
              order = 0, ages = seq(25, 65, by = 5), b = 5, levels = 1, controls = ctl)

head(cv1)
#>   H    type level age holdout k      mse
#> 1 2 forward     1  25    1982 2 1.01e-02
#> 2 2 forward     1  30    1982 2 3.45e-04
#> 3 2 forward     1  35    1982 2 7.08e-05
#> 4 2 forward     1  40    1982 2 4.89e-05
#> 5 2 forward     1  45    1982 2 1.06e-04
#> 6 2 forward     1  50    1982 2 7.13e-05

Each row is one held-out survey (holdout), target age, and window, and mse is the squared prediction error. The attribute "summary" averages over ages and held-out surveys.

cv <- rbind(cbind(extrapolant = "Local-linear fit", attr(cv1, "summary")),
            cbind(extrapolant = "Kernel mean", attr(cv0, "summary")))
cv
#>        extrapolant H    type level     mse
#> 1 Local-linear fit 2 forward     1 0.00683
#> 2 Local-linear fit 3 forward     1 0.00310
#> 3 Local-linear fit 4 forward     1 0.00220
#> 4 Local-linear fit 5 forward     1 0.00181
#> 5      Kernel mean 2 forward     1 0.00166
#> 6      Kernel mean 3 forward     1 0.00147
#> 7      Kernel mean 4 forward     1 0.00151
#> 8      Kernel mean 5 forward     1 0.00146
ggplot(cv, aes(H, sqrt(mse), linetype = extrapolant)) +
  geom_line() + geom_point(size = 1.6) +
  labs(x = "Number of pre-shock surveys H", y = "Root mean squared forward prediction error",
       linetype = NULL) +
  theme_cdd()

Root mean squared forward prediction error against the number of pre-shock surveys for both extrapolants.

Read the plot in the same way as the estimated MSE: a lower value means that this combination predicted held-out pre-shock surveys better. Three features of the criterion matter when reading it.

  • Every squared error contains the sampling variance of the held-out survey mean, which is the same for all H. Differences between windows are therefore informative, and the level is not.
  • A larger H leaves fewer surveys that can be held out, so the criterion for long windows averages over fewer dates and is noisier.
with(cv1, table(H, holdout))
#>    holdout
#> H   1982 1984 1985 1987 1988 1989 1990 1991
#>   2    9    9    9    9    9    9    9    9
#>   3    0    9    9    9    9    9    9    9
#>   4    0    0    9    9    9    9    9    9
#>   5    0    0    0    9    9    9    9    9
  • The argument gap sets how far ahead the prediction is made, counted in surveys. The default gap = 1 predicts the next survey, which matches an exposed survey that is the first one after the shock. The argument max_pre limits the exercise to the most recent pre-shock surveys so that the criterion describes the period near the shock.

cdd_cv(type = "loo") is a different criterion. It leaves out one survey inside the window and predicts it from the others, which is interpolation. It is provided for comparison with earlier applications of the design, and the forward criterion is the one that matches the extrapolation the design performs.

The comparison in an idealized design

cdd_risk_ideal() evaluates the MSE of both extrapolants in closed form for an idealized design with evenly spaced cohorts, equal variances, and a rectangular kernel. It is useful for seeing how the best window responds to the slope beta, the curvature bound M, the error variance sigma2, the number of observations per cohort-year rho, and the extrapolation distance k.

r <- cdd_risk_ideal(h = seq(2, 20, by = 0.5), k = 1, beta = 0.005, M = 0.002,
                    sigma2 = 0.2, rho = 50)
attr(r, "h_star")
#> order0 order1 
#>    3.5   10.5

ideal <- rbind(data.frame(h = r$h, rmse = sqrt(r$risk0), extrapolant = "Kernel mean"),
               data.frame(h = r$h, rmse = sqrt(r$risk1), extrapolant = "Local-linear fit"))
ggplot(ideal, aes(h, rmse, linetype = extrapolant)) +
  geom_line() +
  labs(x = "Window length h (years)", y = "Root MSE", linetype = NULL) +
  theme_cdd()

Closed-form root mean squared error of the kernel mean and the local-linear fit against window length in the idealized design.

The attribute "h_star" gives the minimizing window length for each extrapolant. The local-linear fit prefers a longer window than the kernel mean, because its bias grows with curvature and not with the slope. Raising beta makes the kernel mean worse at every window and leaves the local-linear fit unchanged.