balance_hierarchy function

Aggregation matrix of a (possibly) unbalanced hierarchy in balanced form

Aggregation matrix of a (possibly) unbalanced hierarchy in balanced form

A hierarchy with LL upper levels is said to be balanced if each variable at level ll has at least one child at level l+1l+1. When this doesn't hold, the hierarchy is unbalanced. This function transforms an aggregation matrix of an unbalanced hierarchy into an aggregation matrix of a balanced one. This function is used to reconcile forecasts with cslcc , which operates exclusively with balanced hierarchies.

balance_hierarchy(agg_mat, nodes = "auto", sparse = TRUE)

Arguments

  • agg_mat: A (na×nbn_a \times n_b) numeric matrix representing the cross-sectional aggregation matrix. It maps the nbn_b bottom-level (free) variables into the nan_a upper (constrained) variables.

  • nodes: A (L×1L \times 1) numeric vector indicating the number of variables in each of the upper LL levels of the hierarchy. The default

    value is the string "auto" which calculates the number of variables in each level.

  • sparse: Option to return sparse matrices (default is TRUE).

Returns

A list containing four elements: - bam: The balanced aggregation matrix.

  • agg_mat: The input matrix.

  • nodes: A (L×1L \times 1) numeric vector indicating the number of variables in each of the LL upper levels of the balanced hierarchy.

  • id: The identification number of each variable in the balanced hierarchy. It may contains duplicated values.

Examples

# Unbalanced -> Balanced # T T # |-------| |-------| # A | A B # |---| | |---| | # AA AB B AA AB BA A <- matrix(c(1, 1, 1, 1, 1, 0), 2, byrow = TRUE) obj <- balance_hierarchy(agg_mat = A, nodes = c(1, 1)) obj$bam

See Also

Utilities: FoReco2matrix(), aggts(), commat(), csprojmat(), cstools(), ctprojmat(), cttools(), df2aggmat(), lcmat(), recoinfo(), res2matrix(), shrink_estim(), teprojmat(), tetools(), unbalance_hierarchy()