How to construct cross-basis matrices for DLNMs using dlnm::crossbasis(). Use when specifying exposure-lag-response relationships, choosing basis functions, or setting knot placement.
The cross-basis is the core of DLNM: a bi-dimensional function modeling both the exposure-response and the lag-response simultaneously.
crossbasis() creates a tensor product of two basis functions:
argvar: Basis for the exposure dimension (e.g., temperature → mortality)arglag: Basis for the lag dimension (e.g., how effects are distributed over lag days)cb <- crossbasis(exposure_vector,
lag = 21,
argvar = list(fun = "ns", knots = quantile(exposure, c(.25, .50, .75))),
arglag = list(fun = "ns", knots = logknots(21, 3)))
| Function |
|---|
fun = |
|---|
| Best For |
|---|
| Natural cubic spline | "ns" | Default choice; smooth, well-behaved at boundaries |
| B-spline | "bs" | More flexibility at boundaries |
| P-spline (penalized) | "ps" | Use with cbPen() in GAMs |
| Cubic regression | "cr" | Use with cbPen() in GAMs |
| Linear threshold | "thr" | Simple threshold models |
| Strata (step function) | "strata" | Categorical exposure groups |
quantile(x, c(.10, .75, .90)) for temperature; quantile(x, c(.25, .50, .75)) for pollution.logknots(maxlag, nk) — concentrates knots at shorter lags.df = 3-5 for each dimension. Justify via AIC/BIC or sensitivity.lag: Maximum lag (integer). Typically 21 days for temperature, 1-3 days for acute pollution.group: For stratified analyses (rare).cen: Centering value for the exposure. Set in crosspred(), not here.lag: Required argument. No default.argvar for outcome: argvar describes the exposure, not the outcome.onebasis() check: Use onebasis() first to visualize each marginal basis independently.crossbasis(), onebasis()