Skip to contents

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 a balanced hierarchy into an aggregation matrix of an unbalanced one, by removing possible duplicated series.

Usage

unbalance_hierarchy(agg_mat, more_info = FALSE, sparse = TRUE)

Arguments

agg_mat

A (\(n_a \times n_b\)) numeric matrix representing the cross-sectional aggregation matrix. It maps the \(n_b\) bottom-level (free) variables into the \(n_a\) upper (constrained) variables.

more_info

If TRUE, it returns only the aggregation matrix of the unbalanced hierarchy. Default is FALSE.

sparse

Option to return sparse matrices (default is TRUE).

Value

A list containing four elements (more_info = TRUE):

ubm

The aggregation matrix of the unbalanced hierarchy.

agg_mat

The input matrix.

idrm

The identification number of the duplicated variables (row numbers of the aggregation matrix agg_mat).

id

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

Examples

#     Balanced     ->     Unbalanced
#        T                    T
#    |-------|            |-------|
#    A       B            A       |
#  |---|     |          |---|     |
# AA   AB    BA        AA   AB    BA
A <- matrix(c(1, 1, 1,
              1, 1, 0,
              0, 0, 1), 3, byrow = TRUE)
obj <- unbalance_hierarchy(agg_mat = A)
obj
#> 2 x 3 sparse Matrix of class "dgCMatrix"
#>           
#> [1,] 1 1 1
#> [2,] 1 1 .