## ----setup, include = FALSE--------------------------------------------------- knitr::opts_chunk$set( echo = TRUE, message = FALSE, warning = FALSE, collapse = TRUE, comment = "#>", eval = FALSE ) ## ----temporal----------------------------------------------------------------- # library(gdpar) # # set.seed(1) # n <- 150 # x <- rnorm(n) # # AR(1) errors: serial dependence the working-independence fit ignores. # y <- 1 + 0.5 * x + as.numeric(stats::arima.sim(list(ar = 0.6), n)) # df <- data.frame(x = x, y = y, t = seq_len(n)) # # fit <- gdpar_eb(y ~ x, amm = amm_spec(a = ~ x), data = df, # chains = 2, iter_warmup = 300, iter_sampling = 300) # # # Step 1 — diagnose. Lag-1 autocorrelation, Durbin-Watson, Ljung-Box. # gdpar_dependence_diagnostic(fit, index = df$t) # # # Step 2 — if flagged, re-estimate the uncertainty by a temporal block bootstrap. # gdpar_dependence_robust(fit, data = df, index = df$t, B = 199, seed = 1) ## ----temporal-auto------------------------------------------------------------ # # Data-driven block length: the Politis-White (2004) automatic selector, # # computed from the residuals (no extra refit), with the rate as fallback. # gdpar_dependence_robust(fit, data = df, index = df$t, # block_length = "auto", B = 199, seed = 1) ## ----spatial-diagnostic------------------------------------------------------- # set.seed(2) # n <- 200 # gx <- runif(n); gy <- runif(n) # spatial coordinates # x <- rnorm(n) # # An omitted smooth spatial trend lands in the residuals. # y <- 1 + 0.5 * x + 3 * (gx + gy) + rnorm(n, sd = 0.3) # df <- data.frame(x = x, y = y) # # fit_sp <- gdpar_eb(y ~ x, amm = amm_spec(a = ~ x), data = df, # chains = 2, iter_warmup = 300, iter_sampling = 300) # # gdpar_spatial_dependence_diagnostic(fit_sp, coords = cbind(gx, gy), seed = 1) ## ----spatial-robust----------------------------------------------------------- # gdpar_spatial_dependence_robust(fit_sp, data = df, coords = cbind(gx, gy), # B = 199, seed = 1) ## ----spatial-auto------------------------------------------------------------- # gdpar_spatial_dependence_robust(fit_sp, data = df, coords = cbind(gx, gy), # block_size = "auto", B = 199, seed = 1)