Skip to contents

Two criteria. "forward" holds out the last gap pre-shock waves, fits on the H waves that precede them, and records the squared extrapolation error at the held-out wave; it targets the design's own risk, extrapolation gap waves ahead, and is computed for every feasible holdout position. "loo" leaves one wave inside the window out at a time and predicts it from the others (interpolation), as in the earlier applications.

Usage

cdd_cv(
  data,
  outcome,
  onset,
  grid = 3:8,
  type = c("forward", "loo"),
  gap = 1,
  max_pre = 2 * max(grid),
  b = 5,
  ages = 20:70,
  order = 1,
  kernel = "triangular",
  controls = NULL,
  continuous = FALSE,
  levels = NULL,
  year = "year",
  age = "age",
  weight = "weight",
  ...
)

Arguments

data

A data frame of repeated cross-sections.

outcome

Name of the outcome column. Categorical outcomes are expanded into one linear probability equation per level unless continuous = TRUE.

onset

Onset year of the shock. Pre-shock waves are those strictly before it.

grid

Candidate H values.

type

"forward" or "loo".

gap

For "forward", number of waves held out between the training window and the predicted wave (1 = predict the next wave).

max_pre

For "forward", use only the max_pre most recent pre-shock waves as training and holdout material (default 2 * max(grid)), so that the criterion describes extrapolation in the period near the shock rather than over the whole history of the survey. Inf uses every pre-shock wave.

b

Age half-width; respondents aged a - b to a + b are pooled.

ages

Integer vector of target ages.

order

0 for the kernel-weighted mean, 1 for the local-linear extrapolant.

kernel

Kernel over wave rank, see cdd_kernel().

controls

Character vector of regression terms (e.g. c("factor(race)", "educ")) entering the extrapolation additively. NULL for none.

continuous

Logical; treat the outcome as continuous (single equation).

levels

Optional subset of outcome levels to estimate.

year, age, weight

Names of the survey-year, age, and survey-weight columns.

...

Further arguments passed to cdd() for "forward".

Value

A data frame with H, type, level, age, the held-out wave (forward) and the mean squared prediction error mse; the attribute "summary" averages over ages and holdouts.

Examples

data(gss_culture)
cv <- cdd_cv(gss_culture, "homosex", onset = 1992, grid = 3:5, type = "forward",
             ages = c(30, 50), b = 5, levels = 1)
attr(cv, "summary")
#>   H    type level         mse
#> 1 3 forward     1 0.004667424
#> 2 4 forward     1 0.002948638
#> 3 5 forward     1 0.001705318