| Title: | Hypothesis Testing for Dependent Variables with Unbalanced Data |
|---|---|
| Description: | Implements hierarchical Bayesian inference, robust frequentist inference, and distribution-free inference for dependent and unbalanced data under strong-mixing conditions. Supports triangular-array, weighted-sum and mixingale convergence regimes with Whittle and composite likelihoods, heteroskedasticity-and-autocorrelation-consistent variance estimation, block bootstrap with automatic block length, fixed-bandwidth HAR inference, adaptive conformal prediction, Bayesian decision under Region of Practical Equivalence, bridge-sampling Bayes factors, and predictive comparison via the Widely Applicable Information Criterion and leave-future-out cross-validation. Methods follow Andrews (1991) <doi:10.2307/2938229>, Kiefer and Vogelsang (2005) <doi:10.1017/S0266466605050565>, Patton, Politis and White (2009) <doi:10.1080/07474930802459016>, Vehtari, Gelman and Gabry (2017) <doi:10.1007/s11222-016-9696-4>, Kruschke (2018) <doi:10.1177/2515245918771304>, and Gibbs and Candes (2021) <doi:10.48550/arXiv.2106.00170>. |
| Authors: | Jose Mauricio Gomez Julian [aut, cre] (ORCID: <https://orcid.org/0009-0000-2412-3150>) |
| Maintainer: | Jose Mauricio Gomez Julian <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.0 |
| Built: | 2026-10-14 11:01:46 UTC |
| Source: | https://github.com/IsadoreNabi/HTDV |
Computes the Bayes factor between two fitted htdv_fit
objects via bridge sampling. Requires the bridgesampling package.
htdv_bf(fit1, fit0, ...)htdv_bf(fit1, fit0, ...)
fit1 |
Model in the numerator. |
fit0 |
Model in the denominator. |
... |
Additional arguments passed to
|
A list with bf10, log_bf10, logml1,
logml0, and error_percentage.
Meng, X.-L., & Wong, W.H. (1996). Simulating Ratios of Normalizing Constants. Statistica Sinica 6(4): 831-860. Gronau, Q.F. et al. (2017). A Tutorial on Bridge Sampling. JMP 81: 80-97.
if (requireNamespace("bridgesampling", quietly = TRUE)) { x <- rnorm(50) f1 <- htdv_fit(x, model = "tac", chains = 2, iter = 500, refresh = 0, seed = 1) f0 <- htdv_fit(x, model = "tac", chains = 2, iter = 500, refresh = 0, seed = 2) htdv_bf(f1, f0)$bf10 }if (requireNamespace("bridgesampling", quietly = TRUE)) { x <- rnorm(50) f1 <- htdv_fit(x, model = "tac", chains = 2, iter = 500, refresh = 0, seed = 1) f0 <- htdv_fit(x, model = "tac", chains = 2, iter = 500, refresh = 0, seed = 2) htdv_bf(f1, f0)$bf10 }
Implements circular and stationary block bootstraps (Politis-Romano 1992, 1994) with Patton-Politis-White (2009) automatic block length selection.
htdv_boot( x, statistic, R = 1999L, type = c("circular", "stationary"), block_length = "auto", level = 0.95, seed = NULL )htdv_boot( x, statistic, R = 1999L, type = c("circular", "stationary"), block_length = "auto", level = 0.95, seed = NULL )
x |
Numeric vector. |
statistic |
Function |
R |
Number of bootstrap replicates. |
type |
|
block_length |
Either |
level |
Confidence level for intervals. |
seed |
Optional integer seed. |
A list with t0 (statistic on original data), t_star
(bootstrap distribution), ci_percentile, ci_basic,
ci_studentized, and block_length.
Politis, D.N., & Romano, J.P. (1994). The Stationary Bootstrap. JASA 89(428): 1303-1313. Patton, A., Politis, D.N., & White, H. (2009). Correction to Automatic Block-Length Selection for the Dependent Bootstrap. Econometric Reviews 28(4): 372-375.
x <- arima.sim(model = list(ar = 0.5), n = 200, rand.gen = rnorm) out <- htdv_boot(as.numeric(x), mean, R = 500, type = "stationary", seed = 1) out$ci_percentilex <- arima.sim(model = list(ar = 0.5), n = 200, rand.gen = rnorm) out <- htdv_boot(as.numeric(x), mean, R = 500, type = "stationary", seed = 1) out$ci_percentile
Pairwise or k-tuple composite log-likelihood (Varin, Reid and Firth
2011) for strictly stationary sequences.
htdv_composite(x, density_fun, theta, k = 1L, log = FALSE)htdv_composite(x, density_fun, theta, k = 1L, log = FALSE)
x |
Numeric vector. |
density_fun |
Function |
theta |
Numeric parameter vector. |
k |
Window width (pairwise if |
log |
Logical; if |
A list with loglik (scalar), n_blocks, and
block_values.
Varin, C., Reid, N., & Firth, D. (2011). An overview of composite likelihood methods. Statistica Sinica, 21(1), 5-42.
x <- arima.sim(model = list(ar = 0.4), n = 200, rand.gen = rnorm) gauss_ar1 <- function(block, theta) { phi <- theta[1]; sigma2 <- theta[2] a <- block[1]; b <- block[2] dnorm(a, 0, sqrt(sigma2 / (1 - phi^2)), log = TRUE) + dnorm(b, phi * a, sqrt(sigma2), log = TRUE) } htdv_composite(as.numeric(x), gauss_ar1, c(0.4, 1), k = 1, log = TRUE)$loglikx <- arima.sim(model = list(ar = 0.4), n = 200, rand.gen = rnorm) gauss_ar1 <- function(block, theta) { phi <- theta[1]; sigma2 <- theta[2] a <- block[1]; b <- block[2] dnorm(a, 0, sqrt(sigma2 / (1 - phi^2)), log = TRUE) + dnorm(b, phi * a, sqrt(sigma2), log = TRUE) } htdv_composite(as.numeric(x), gauss_ar1, c(0.4, 1), k = 1, log = TRUE)$loglik
Online adaptive conformal prediction intervals with gradient update on the miscoverage rate (Gibbs-Candes 2021). Provides long-run marginal coverage without exchangeability.
htdv_conformal( x, predictor, residual_fun = function(e) abs(e), alpha_target = 0.1, lambda = 0.05, burn_in = 20L )htdv_conformal( x, predictor, residual_fun = function(e) abs(e), alpha_target = 0.1, lambda = 0.05, burn_in = 20L )
x |
Numeric vector of sequential observations. |
predictor |
Function |
residual_fun |
Function of residuals to calibrate the score; default absolute residual. |
alpha_target |
Target miscoverage rate. |
lambda |
Step size for the gradient update. |
burn_in |
Integer; the first |
A list with intervals (matrix of lower/upper),
coverage (empirical), alpha_path, and
point_predictions.
Gibbs, I., & Candes, E. (2021). Adaptive Conformal Inference under Distribution Shift. NeurIPS 34: 1660-1672.
x <- arima.sim(model = list(ar = 0.6), n = 200, rand.gen = rnorm) pred <- function(hist) if (length(hist) >= 1) hist[length(hist)] else 0 out <- htdv_conformal(as.numeric(x), pred, alpha_target = 0.1, lambda = 0.05, burn_in = 20) out$coveragex <- arima.sim(model = list(ar = 0.6), n = 200, rand.gen = rnorm) pred <- function(hist) if (length(hist) >= 1) hist[length(hist)] else 0 out <- htdv_conformal(as.numeric(x), pred, alpha_target = 0.1, lambda = 0.05, burn_in = 20) out$coverage
Computes split-Rhat, bulk and tail ESS, E-BFMI, divergence count, and treedepth saturation; all standard HMC diagnostics (Vehtari et al. 2021, Betancourt 2016).
htdv_diagnostics( fit, rhat_threshold = 1.01, ess_threshold = 400, bfmi_threshold = 0.3 )htdv_diagnostics( fit, rhat_threshold = 1.01, ess_threshold = 400, bfmi_threshold = 0.3 )
fit |
An |
rhat_threshold |
Convergence threshold for Rhat. |
ess_threshold |
Minimum effective sample size. |
bfmi_threshold |
Minimum acceptable energy-BFMI. |
A list with rhat, ess_bulk, ess_tail,
bfmi, divergences, max_treedepth,
passed (logical), and failures (character vector).
Vehtari, A., Gelman, A., Simpson, D., Carpenter, B., & Buerkner, P.-C. (2021). Rank-normalization, folding, and localization: An improved Rhat for assessing convergence of MCMC. Bayesian Analysis 16(2): 667-718. Betancourt, M. (2016). Diagnosing Suboptimal Cotangent Disintegrations. <doi:10.48550/arXiv.1604.00695>.
x <- rnorm(50) fit <- htdv_fit(x, model = "tac", chains = 2, iter = 500, refresh = 0, seed = 1) htdv_diagnostics(fit)$passedx <- rnorm(50) fit <- htdv_fit(x, model = "tac", chains = 2, iter = 500, refresh = 0, seed = 1) htdv_diagnostics(fit)$passed
Output of the three-dataset external validation protocol of Section 12-ter of the companion paper. Each dataset is run against a pre-existing reference result from the published literature on the same vintage, with the three HTDV inferential layers (HAR, bootstrap, hierarchical Bayesian) reporting their point estimate, 95% interval, and a Bayesian diagnostic-pass flag.
htdv_empirical_benchmarkshtdv_empirical_benchmarks
A data frame with three rows (one per dataset) and the following columns:
Name of the benchmark dataset.
Citation of the reference paper.
Sample size after preprocessing.
Sample window (string).
Reference point value.
Reference standard error (NA when the
reference does not provide one).
HAR-Wald point and 95% CI.
Bayesian point and 95% credible interval.
Bayesian HMC diagnostics.
Stationary block bootstrap point and 95% percentile CI.
Per-layer
agreement verdict: "agreement", "htdv-strict (above ref)",
or "htdv-strict (below ref)".
The three benchmarks (E1, E2, E3) and their references are:
E1. Post-1984 US CPI inflation against Stock and
Watson (2007). FRED-MD vintage 2026-03, variable CPIAUCSL
transformed to annualized monthly inflation.
E2. Long-run mean of log-CAPE against Campbell and Shiller (1998). Robert Shiller's online historical dataset.
E3. US vs. Canada 10-year government bond yield
differential against the iid Welch baseline. FRED series
GS10 and IRLTLT01CAM156N, common sample 1990-01 to
latest.
Generated by run_benchmarks.R of the companion paper
repository. See vignette("HTDV-validation") for the
methodological narrative and the persistence-ladder reading.
Builds an envelope posterior over a list of htdv_fit objects by
entropy-maximizing mixture weights subject to predictive consistency
(Berger 1994).
htdv_envelope(fits, target = "theta")htdv_envelope(fits, target = "theta")
fits |
List of |
target |
Name of the Stan parameter over which to build the envelope. |
A list with draws (envelope draws for the target parameter),
weights, intervals, and component_intervals.
Berger, J.O. (1994). An Overview of Robust Bayesian Analysis. Test 3(1): 5-124.
x <- rnorm(50) f1 <- htdv_fit(x, model = "tac", chains = 2, iter = 500, refresh = 0, seed = 1) f2 <- htdv_fit(x, model = "wsc", chains = 2, iter = 500, refresh = 0, seed = 2) htdv_envelope(list(f1, f2), target = "theta")$intervalsx <- rnorm(50) f1 <- htdv_fit(x, model = "tac", chains = 2, iter = 500, refresh = 0, seed = 1) f2 <- htdv_fit(x, model = "wsc", chains = 2, iter = 500, refresh = 0, seed = 2) htdv_envelope(list(f1, f2), target = "theta")$intervals
Computes the explicit finite-sample constants K_TAC(gamma, q), K_MPC(gamma) and the unified two-sided envelope (c_L, c_U) from Theorems 5-8 of the companion paper.
htdv_equivalence_constants(gamma, q = 6, n = 100, C_alpha = 1)htdv_equivalence_constants(gamma, q = 6, n = 100, C_alpha = 1)
gamma |
Mixing decay rate; must satisfy |
q |
Moment order used in Ibragimov-Rio covariance bound; must satisfy
|
n |
Sample size used for the two-sided envelope. |
C_alpha |
Strong-mixing constant (default 1). |
A list with components K_TAC, K_MPC, c_L,
c_U, b_optimal, m_optimal, and regime
(a short label describing which method is favored).
htdv_equivalence_constants(gamma = 2, q = 6, n = 60)htdv_equivalence_constants(gamma = 2, q = 6, n = 60)
Fits the hierarchical Bayesian model described in the companion paper via
Hamiltonian Monte Carlo (NUTS) using rstan. Nuisance parameters
sigma_inf, gamma_mix, and (for WSC) b carry priors and
are integrated over.
htdv_fit( x, model = c("tac", "wsc", "mpc", "whittle", "composite"), chains = 4L, iter = 4000L, warmup = iter%/%2L, refresh = max(iter%/%10L, 1L), adapt_delta = 0.99, max_treedepth = 12L, seed = NULL, ... ) htdv_tac(x, ...) htdv_wsc(x, ...) htdv_mpc(x, ...)htdv_fit( x, model = c("tac", "wsc", "mpc", "whittle", "composite"), chains = 4L, iter = 4000L, warmup = iter%/%2L, refresh = max(iter%/%10L, 1L), adapt_delta = 0.99, max_treedepth = 12L, seed = NULL, ... ) htdv_tac(x, ...) htdv_wsc(x, ...) htdv_mpc(x, ...)
x |
Numeric vector of observations. |
model |
One of |
chains |
Number of HMC chains. |
iter |
Total iterations per chain (warmup plus sampling). |
warmup |
Number of warmup iterations. |
refresh |
Stan progress refresh rate (0 suppresses output). |
adapt_delta |
HMC adaptation target acceptance. |
max_treedepth |
Maximum NUTS treedepth. |
seed |
Optional integer seed forwarded to rstan. |
... |
Additional arguments forwarded to |
An object of class htdv_fit, a list with components
stanfit, model, data, n, call.
Hoffman, M.D., & Gelman, A. (2014). The No-U-Turn Sampler. JMLR 15(1): 1593-1623. Betancourt, M. (2016). Diagnosing Suboptimal Cotangent Disintegrations in HMC. <doi:10.48550/arXiv.1604.00695>.
x <- rnorm(50) fit <- htdv_fit(x, model = "tac", chains = 2, iter = 500, refresh = 0, seed = 1) class(fit)x <- rnorm(50) fit <- htdv_fit(x, model = "tac", chains = 2, iter = 500, refresh = 0, seed = 1) class(fit)
Fixed-b HAR Wald test where the bandwidth is a fixed fraction of the sample size. Critical values are obtained by simulation from the asymptotic functional distribution.
htdv_fixedb( x, theta0 = 0, B = 0.1, kernel = c("bartlett", "parzen", "qs"), sims = 5000L, alpha = 0.05, seed = NULL )htdv_fixedb( x, theta0 = 0, B = 0.1, kernel = c("bartlett", "parzen", "qs"), sims = 5000L, alpha = 0.05, seed = NULL )
x |
Numeric vector. |
theta0 |
Null value for the mean (default 0). |
B |
Fixed bandwidth fraction in (0, 1]. |
kernel |
Kernel choice (see |
sims |
Number of Monte Carlo draws for the critical-value simulation. |
alpha |
Significance level. |
seed |
Optional integer seed for reproducibility. NULL leaves the user's RNG state untouched. |
A list with statistic, critical_value, p_value,
reject, bandwidth, and kernel.
Kiefer, N.M., & Vogelsang, T.J. (2005). A New Asymptotic Theory for Heteroskedasticity-Autocorrelation Robust Tests. Econometric Theory 21(6): 1130-1164.
x <- arima.sim(model = list(ar = 0.5), n = 200, rand.gen = rnorm) htdv_fixedb(as.numeric(x), theta0 = 0, B = 0.2, sims = 1000, seed = 1)$p_valuex <- arima.sim(model = list(ar = 0.5), n = 200, rand.gen = rnorm) htdv_fixedb(as.numeric(x), theta0 = 0, B = 0.2, sims = 1000, seed = 1)$p_value
Heteroskedasticity-and-autocorrelation-consistent long-run variance with data-driven Andrews (1991) optimal bandwidth, Bartlett, Parzen, and Quadratic-Spectral kernels.
htdv_lrv( x, kernel = c("bartlett", "parzen", "qs"), bandwidth = "andrews", prewhiten = FALSE )htdv_lrv( x, kernel = c("bartlett", "parzen", "qs"), bandwidth = "andrews", prewhiten = FALSE )
x |
Numeric vector of observations. |
kernel |
Kernel choice: |
bandwidth |
Either |
prewhiten |
Logical; if |
A list with components lrv (long-run variance estimate),
bandwidth, kernel, and ar_coef (only if prewhitened).
Andrews, D.W.K. (1991). Heteroskedasticity and Autocorrelation Consistent Covariance Matrix Estimation. Econometrica 59(3): 817-858. Newey, W.K. & West, K.D. (1987). A Simple, Positive Semi-Definite Heteroskedasticity and Autocorrelation Consistent Covariance Matrix. Econometrica 55(3): 703-708.
set_seed_user <- 42 x <- arima.sim(model = list(ar = 0.6), n = 200, rand.gen = rnorm) out <- htdv_lrv(as.numeric(x), kernel = "qs", bandwidth = "andrews") out$lrvset_seed_user <- 42 x <- arima.sim(model = list(ar = 0.6), n = 200, rand.gen = rnorm) out <- htdv_lrv(as.numeric(x), kernel = "qs", bandwidth = "andrews") out$lrv
Replicates autocorrelation, Ljung-Box, spectral discrepancy, and a
detrended-fluctuation Hurst exponent under the posterior and computes
posterior-predictive p-values.
htdv_ppc(fit, x_obs, lag_max = 10L)htdv_ppc(fit, x_obs, lag_max = 10L)
fit |
An |
x_obs |
The observed data vector. |
lag_max |
Maximum lag for autocorrelation. |
A list with p_acf, p_ljung_box, p_spectral,
p_hurst.
x <- rnorm(50) fit <- htdv_fit(x, model = "tac", chains = 2, iter = 500, refresh = 0, seed = 1) htdv_ppc(fit, x)x <- rnorm(50) fit <- htdv_fit(x, model = "tac", chains = 2, iter = 500, refresh = 0, seed = 1) htdv_ppc(fit, x)
Posterior decision under Kruschke's (2018) Region of Practical Equivalence.
htdv_rope(draws, rope, level = 0.95)htdv_rope(draws, rope, level = 0.95)
draws |
Numeric vector of posterior draws of the parameter of interest. |
rope |
Length-2 numeric vector |
level |
Credibility level for the highest-density interval. |
A list with decision ("accept", "reject",
"undecided"), hdi, rope, and prob_in_rope.
Kruschke, J.K. (2018). Rejecting or Accepting Parameter Values in Bayesian Estimation. Advances in Methods and Practices in Psychological Science 1(2): 270-280.
draws <- rnorm(4000, mean = 0.05, sd = 0.1) htdv_rope(draws, rope = c(-0.1, 0.1), level = 0.95)$decisiondraws <- rnorm(4000, mean = 0.05, sd = 0.1) htdv_rope(draws, rope = c(-0.1, 0.1), level = 0.95)$decision
Sign-corrected aggregated results of the factorial Monte Carlo study described in Section 12-bis of the companion paper. The study crosses five factors at four levels each (sample size, AR(1) coefficient, innovation tail, imbalance ratio, location shift) for 1024 cells, each replicated 500 times against three inferential layers (HAR, bootstrap, hierarchical Bayesian). One cell (n=500, phi=0.85, t3, imb=1, delta=0) was lost to an I/O collision and is excluded; the table contains 1023 cells x 3 layers = 3069 rows.
htdv_sim_summaryhtdv_sim_summary
A data frame with one row per (cell, layer) and the following columns:
Per-group primary sample size (40, 80, 200, 500).
AR(1) coefficient (0, 0.3, 0.6, 0.85).
Innovation distribution: "normal", "t5",
"t3", "t2_1".
Imbalance ratio n1/n2 (1, 1.5, 3, 6).
Location shift in units of sigma_inf (0, 0.1, 0.25, 0.5).
Inferential layer: "har", "boot",
"bayes".
Number of replications aggregated (500 for all cells).
Empirical rejection rate at nominal alpha = 0.05.
Fraction of replications whose 95% interval covered the true parameter (sign-corrected for HAR and bootstrap).
Average length of the 95% interval.
Mean per-replication runtime in seconds.
Fraction of replications passing all HMC
diagnostic gates (Bayesian layer only; NA otherwise).
Generated by run_simstudy.R of the companion paper
repository on master seed 20260422, with sign-corrected
coverage produced by recover_coverage.R. Total wall-clock
31.1 hours on a 16-core Linux workstation. See
vignette("HTDV-validation") for the full report.
Runs the pre-registered factorial Monte Carlo study of Section 12-bis of the companion paper. The study crosses four factors (per-group sample size, AR(1) coefficient, innovation tail, imbalance ratio) and evaluates three inferential layers (HAR-Wald, stationary block bootstrap, hierarchical Bayesian HMC) on each replication.
htdv_simstudy( n_grid = c(40L, 80L, 200L, 500L), phi_grid = c(0, 0.3, 0.6, 0.85), tail_grid = c("normal", "t5", "t3", "t2_1"), imb_grid = c(1, 1.5, 3, 6), delta_grid = c(0, 0.1, 0.25, 0.5), R = 500L, seed = 20260422L, n_cores = 1L, layers = c("har", "boot", "bayes"), bayes_chains = 2L, bayes_iter = 600L, bayes_warmup = 300L, boot_R = 999L, rope = c(-0.1, 0.1), alpha = 0.05, out_dir = NULL, progress = TRUE )htdv_simstudy( n_grid = c(40L, 80L, 200L, 500L), phi_grid = c(0, 0.3, 0.6, 0.85), tail_grid = c("normal", "t5", "t3", "t2_1"), imb_grid = c(1, 1.5, 3, 6), delta_grid = c(0, 0.1, 0.25, 0.5), R = 500L, seed = 20260422L, n_cores = 1L, layers = c("har", "boot", "bayes"), bayes_chains = 2L, bayes_iter = 600L, bayes_warmup = 300L, boot_R = 999L, rope = c(-0.1, 0.1), alpha = 0.05, out_dir = NULL, progress = TRUE )
n_grid |
Integer vector of primary sample sizes |
phi_grid |
Numeric vector of AR(1) coefficients in |
tail_grid |
Character vector; any subset of |
imb_grid |
Numeric vector of imbalance ratios |
delta_grid |
Numeric vector of location shifts in units of
|
R |
Integer number of Monte Carlo replications per cell. |
seed |
Integer master seed. |
n_cores |
Integer number of workers for cell-level parallelism. On non-Unix platforms parallelism falls back to serial. |
layers |
Character vector; any subset of |
bayes_chains |
Number of HMC chains per Bayesian fit. |
bayes_iter |
Total HMC iterations (warmup + sampling). |
bayes_warmup |
HMC warmup iterations. |
boot_R |
Bootstrap replicates per call. |
rope |
Length-2 numeric vector; ROPE for the Bayesian decision on the raw (non-standardized) delta. |
alpha |
Significance level (nominal size of tests; |
out_dir |
Optional directory for per-cell incremental RDS results.
Each cell is written to its own |
progress |
Logical; print a one-line status per completed cell. |
A data frame with one row per (cell, replication, layer). Columns:
cell_id, n, phi, tail, imb, n1, n2, delta, sigma_inf, layer,
replicate, reject, ci_lo, ci_hi, estimate, covered, ci_length,
rhat_max, ess_min, divergences, diag_pass, runtime_sec.
Two independent AR(1) series of length and
of length
are generated. The innovations are drawn from rnorm,
scaled Student-, scaled Student- or scaled
Student- so that the nominal innovation variance is one
when the law has a finite second moment. Group one has mean zero; group
two has mean where
.
HAR-Wald ("har"). Welch-style two-sample statistic
with long-run variances estimated via htdv_lrv (QS
kernel, Andrews bandwidth) on each group's demeaned series.
Rejection at asymptotic critical value.
Stationary block bootstrap ("boot"). Each group
resampled independently using
htdv_boot with block_length = "auto" (Patton-
Politis-White). Percentile interval on
.
Hierarchical Bayesian ("bayes"). Two-sample AR(1)
Stan model (simstudy_two_sample.stan); posterior interval on
. A run is flagged
diag_pass = TRUE only if , bulk and tail
ESS above , and zero divergences.
Kiefer, N.M., & Vogelsang, T.J. (2005). Econometric Theory 21(6): 1130-1164. Patton, A., Politis, D.N., & White, H. (2009). Econometric Reviews 28(4): 372-375. Kruschke, J.K. (2018). Advances in Methods and Practices in Psychological Science 1(2): 270-280.
res <- htdv_simstudy(n_grid = c(40, 80), phi_grid = c(0, 0.6), tail_grid = c("normal"), imb_grid = c(1, 3), delta_grid = c(0, 0.25), R = 5L, n_cores = 1L, layers = c("har", "boot")) head(htdv_simstudy_summary(res))res <- htdv_simstudy(n_grid = c(40, 80), phi_grid = c(0, 0.6), tail_grid = c("normal"), imb_grid = c(1, 3), delta_grid = c(0, 0.25), R = 5L, n_cores = 1L, layers = c("har", "boot")) head(htdv_simstudy_summary(res))
Computes empirical size (or rejection rate), coverage, and mean interval
length per (cell x layer) from the raw output of htdv_simstudy.
htdv_simstudy_summary(res, alpha = 0.05)htdv_simstudy_summary(res, alpha = 0.05)
res |
Data frame returned by |
alpha |
Nominal size used in the study (must match what
|
A data frame with one row per (cell, layer) and columns
n, phi, tail, imb, delta, layer, n_reps, reject_rate, coverage,
mean_ci_length, mean_runtime, diag_pass_rate.
res <- htdv_simstudy(n_grid = c(40), phi_grid = c(0.3), tail_grid = "normal", imb_grid = 1, delta_grid = c(0, 0.3), R = 5, layers = c("har")) htdv_simstudy_summary(res)res <- htdv_simstudy(n_grid = c(40), phi_grid = c(0.3), tail_grid = "normal", imb_grid = 1, delta_grid = c(0, 0.3), R = 5, layers = c("har")) htdv_simstudy_summary(res)
Reads an aggregated htdv_simstudy_summary output and returns
the subset of cells where the Bayesian diagnostic-pass rate falls below a
user-set threshold. Such cells are typically located in the corner of the
design where strong autocorrelation meets a small sample (high
and low ); the AR(1) likelihood there approaches its limit of
identification, MCMC diagnostics flag the resulting posterior, and
practitioners should treat the cell with extra caution—either by
increasing HMC iterations, tightening the priors on , or
falling back to the conformal anchor whose validity does not require
identifiability.
htdv_simstudy_warnings(summ, threshold = 0.7)htdv_simstudy_warnings(summ, threshold = 0.7)
summ |
Data frame from |
threshold |
Minimum acceptable Bayesian |
A data frame with the columns n, phi, tail, imb, delta,
layer, diag_pass_rate, restricted to Bayesian rows whose pass rate is
below threshold, plus an integer column flag_index
(sequential identifier of flagged cells, useful for cross-referencing
in reports and in vignettes).
res <- htdv_simstudy(n_grid = c(40, 200), phi_grid = c(0, 0.85), tail_grid = "normal", imb_grid = c(1, 6), delta_grid = c(0, 0.25), R = 50L) summ <- htdv_simstudy_summary(res) htdv_simstudy_warnings(summ, threshold = 0.7)res <- htdv_simstudy(n_grid = c(40, 200), phi_grid = c(0, 0.85), tail_grid = "normal", imb_grid = c(1, 6), delta_grid = c(0, 0.25), R = 50L) summ <- htdv_simstudy_summary(res) htdv_simstudy_warnings(summ, threshold = 0.7)
Computes stacking weights (Yao, Vehtari, Simpson, Gelman 2018) across a list of fitted models by LOO-log-score maximization.
htdv_stack(fits, method = c("log_score"))htdv_stack(fits, method = c("log_score"))
fits |
Named list of |
method |
Stacking objective. Only |
A list with weights, model_names, and
elpd_per_model.
if (requireNamespace("loo", quietly = TRUE)) { x <- rnorm(50) f1 <- htdv_fit(x, model = "tac", chains = 2, iter = 500, refresh = 0, seed = 1) f2 <- htdv_fit(x, model = "wsc", chains = 2, iter = 500, refresh = 0, seed = 2) htdv_stack(list(tac = f1, wsc = f2))$weights }if (requireNamespace("loo", quietly = TRUE)) { x <- rnorm(50) f1 <- htdv_fit(x, model = "tac", chains = 2, iter = 500, refresh = 0, seed = 1) f2 <- htdv_fit(x, model = "wsc", chains = 2, iter = 500, refresh = 0, seed = 2) htdv_stack(list(tac = f1, wsc = f2))$weights }
Print-Friendly Summary for an HTDV Fit
htdv_summary(fit, rope = NULL, target = "theta")htdv_summary(fit, rope = NULL, target = "theta")
fit |
An |
rope |
Optional two-element vector for ROPE decision on the target. |
target |
Parameter name to summarize. |
A data frame with posterior mean, sd, 2.5%, 50%, 97.5%, Rhat,
bulk and tail ESS for target, plus the ROPE decision if requested.
x <- rnorm(50) fit <- htdv_fit(x, model = "tac", chains = 2, iter = 500, refresh = 0, seed = 1) htdv_summary(fit, target = "theta")x <- rnorm(50) fit <- htdv_fit(x, model = "tac", chains = 2, iter = 500, refresh = 0, seed = 1) htdv_summary(fit, target = "theta")
Computes the Widely Applicable Information Criterion (Watanabe 2010) and
leave-future-out expected log predictive density (Buerkner-Gabry-Vehtari
2020) from a fitted htdv_fit object.
htdv_waic_lfo(fit, L = NULL, k_threshold = 0.7)htdv_waic_lfo(fit, L = NULL, k_threshold = 0.7)
fit |
An |
L |
Block-prefix length; leave-future-out starts at time |
k_threshold |
Pareto-k refresh threshold; when exceeded, importance sampling is refreshed. |
A list with waic, elpd_lfo, elpd_se,
pareto_k, and refresh_times.
Watanabe, S. (2010). Asymptotic Equivalence of Bayes Cross Validation and Widely Applicable Information Criterion. JMLR 11: 3571-3594. Buerkner, P.-C., Gabry, J., & Vehtari, A. (2020). Approximate Leave-Future-Out Cross-Validation for Bayesian Time Series Models. Journal of Statistical Computation and Simulation 90(14): 2499-2523.
if (requireNamespace("loo", quietly = TRUE)) { x <- rnorm(50) fit <- htdv_fit(x, model = "tac", chains = 2, iter = 500, refresh = 0, seed = 1) htdv_waic_lfo(fit)$waic }if (requireNamespace("loo", quietly = TRUE)) { x <- rnorm(50) fit <- htdv_fit(x, model = "tac", chains = 2, iter = 500, refresh = 0, seed = 1) htdv_waic_lfo(fit)$waic }
Computes the Whittle pseudo-log-likelihood at Fourier frequencies for a user-supplied spectral density.
htdv_whittle(x, spec_fun, theta, taper = FALSE)htdv_whittle(x, spec_fun, theta, taper = FALSE)
x |
Numeric vector. |
spec_fun |
Function |
theta |
Numeric parameter vector passed to |
taper |
Logical; if |
A list with loglik (scalar), frequencies,
periodogram, and fitted_spectrum.
Whittle, P. (1953). Estimation and Information in Stationary Time Series. Arkiv foer Matematik, 2(5), 423-434. Dzhaparidze, K. (1986). Parameter Estimation and Hypothesis Testing in Spectral Analysis of Stationary Time Series. Springer.
x <- arima.sim(model = list(ar = 0.5), n = 200, rand.gen = rnorm) ar1_spec <- function(lambda, theta) { phi <- theta[1]; sigma2 <- theta[2] sigma2 / (2 * pi * (1 - 2 * phi * cos(lambda) + phi^2)) } htdv_whittle(as.numeric(x), ar1_spec, c(0.5, 1))$loglikx <- arima.sim(model = list(ar = 0.5), n = 200, rand.gen = rnorm) ar1_spec <- function(lambda, theta) { phi <- theta[1]; sigma2 <- theta[2] sigma2 / (2 * pi * (1 - 2 * phi * cos(lambda) + phi^2)) } htdv_whittle(as.numeric(x), ar1_spec, c(0.5, 1))$loglik