Learn R Programming

BayesianDisaggregation (version 0.1.2)

bayesian_disaggregate: Run Bayesian disaggregation

Description

Performs Bayesian disaggregation of an aggregated time series (e.g., CPI) into \(K\) components using one of four deterministic update rules: weighted, multiplicative, dirichlet, adaptive.

Usage

bayesian_disaggregate(
  path_cpi,
  path_weights,
  method = c("weighted", "multiplicative", "dirichlet", "adaptive"),
  lambda = 0.7,
  gamma = 0.1,
  coh_mult = 3,
  coh_const = 0.5,
  stab_a = 1000,
  stab_b = 10,
  stab_kappa = 50,
  likelihood_pattern = "recent"
)

Value

A list with:

years

Integer vector of years used.

industries

Character vector of sector/column names.

prior

Tibble prior \(T \times (1+K)\) with Year then sectors.

likelihood_t

Tibble likelihood over time (same shape as prior).

likelihood

Tibble Sector, L (length \(K\)).

posterior

Tibble posterior \(T \times (1+K)\) (rows sum to 1).

metrics

Tibble with hyperparameters + coherence, stability, interpretability, efficiency, composite, T, K.

Arguments

path_cpi

Path to the CPI Excel file. Must contain at least the columns date and value (case/locale tolerant in read_cpi()).

path_weights

Path to the Excel file with the baseline weight matrix (prior): either \(T \times K\) (years in rows, sectors in columns) or a length-\(K\) vector (constant across time). Rows are renormalized to the simplex.

method

Disaggregation method: "weighted", "multiplicative", "dirichlet", or "adaptive".

lambda

Weight for the "weighted" method in \([0,1]\). Ignored otherwise.

gamma

Uncertainty factor for the "dirichlet" method (\(> 0\)).

coh_mult

Multiplier for the coherence increment \(\Delta\rho\).

coh_const

Constant offset for coherence, truncated to \([0,1]\).

stab_a

Sensitivity for row-sum deviation penalty \(| \sum w - 1 |\).

stab_b

Sensitivity for negative-values penalty (count of negatives).

stab_kappa

Sensitivity for temporal variation (average \(|\Delta|\)).

likelihood_pattern

Temporal spreading pattern for the likelihood: "constant", "recent", "linear", or "bell".

Details

Assumptions: (i) prior/posterior rows lie on the simplex; (ii) no MCMC is used, updates are analytic/deterministic; (iii) read_* helpers coerce benign formatting issues and error on malformed inputs.

See Also

read_cpi, read_weights_matrix, compute_L_from_P, spread_likelihood, posterior_weighted, posterior_multiplicative, posterior_dirichlet, posterior_adaptive, coherence_score, stability_composite, interpretability_score

Examples

Run this code
# \donttest{
# Minimal synthetic run (no files):
T <- 6; K <- 4
P <- matrix(rep(1/K, T*K), nrow = T)
L <- runif(K); L <- L/sum(L)
LT <- spread_likelihood(L, T, "recent")
W  <- posterior_weighted(P, LT, lambda = 0.7)
# }

Run the code above in your browser using DataLab