Time series data structures and diagnostics in R. Use when working with ts, zoo, xts objects, autocorrelation, or handling irregular time series.
| Class | Package | Best For |
|---|---|---|
ts | base R | Regular, single-frequency series |
zoo | zoo | Irregular time series, flexible index |
xts | xts | Finance-style with date-time index |
data.frame | base R | DLNM work (column-based, with date column) |
Most DLNM analyses use plain data.frame or tibble with a date column, not ts objects:
df <- data.frame(date = seq(as.Date("2000-01-01"), as.Date("2019-12-31"), by = "day"))
df <- left_join(df, mortality_data, by = "date")
df <- left_join(df, exposure_data, by = "date")
# After fitting a model, check residuals
res <- residuals(model, type = "deviance")
acf(res, main = "ACF of Deviance Residuals")
pacf(res, main = "PACF of Deviance Residuals")
tidyr::complete(date = full_seq(date, 1)).diff(df$date) — values ≠ 1 indicate missing days.crossbasis().tseries::adf.test(x) — tests for unit root.tseries::kpss.test(x) — tests for stationarity.