Aggregation matrix of a (possibly) unbalanced hierarchy in balanced form
Aggregation matrix of a (possibly) unbalanced hierarchy in balanced form
A hierarchy with L upper levels is said to be balanced if each variable at level l has at least one child at level l+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.
agg_mat: A (na×nb) numeric matrix representing the cross-sectional aggregation matrix. It maps the nb bottom-level (free) variables into the na upper (constrained) variables.
nodes: A (L×1) numeric vector indicating the number of variables in each of the upper L 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×1) numeric vector indicating the number of variables in each of the L 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 BAA <- matrix(c(1,1,1,1,1,0),2, byrow =TRUE)obj <- balance_hierarchy(agg_mat = A, nodes = c(1,1))obj$bam