df2aggmat | R Documentation |
This function allows the user to easily build the (n_a \times n_b
)
cross-sectional aggregation matrix starting from a data frame.
df2aggmat(formula, data, sep = "_", sparse = TRUE, top_label = "Total",
verbose = TRUE)
formula |
Specification of the hierarchical structure: grouped hierarchies are specified
using |
data |
A dataset in which each column contains the values of the variables in the formula and each row identifies a bottom level time series. |
sep |
Character to separate the names of the aggregated series, (default is " |
sparse |
Option to return sparse matrices (default is |
top_label |
Label of the top level variable (default is " |
verbose |
If |
A (na x nb
) matrix.
Utilities:
FoReco2matrix()
,
aggts()
,
balance_hierarchy()
,
commat()
,
csprojmat()
,
cstools()
,
ctprojmat()
,
cttools()
,
lcmat()
,
recoinfo()
,
res2matrix()
,
shrink_estim()
,
teprojmat()
,
tetools()
,
unbalance_hierarchy()
## Balanced hierarchy
# T
# |--------|
# A B
# |---| |--|--|
# AA AB BA BB BC
# Names of the bottom level variables
data_bts <- data.frame(X1 = c("A", "A", "B", "B", "B"),
X2 = c("A", "B", "A", "B", "C"),
stringsAsFactors = FALSE)
# Cross-sectional aggregation matrix
agg_mat <- df2aggmat(~ X1 / X2, data_bts, sep = "", verbose = FALSE)
## Unbalanced hierarchy
# T
# |---------|---------|
# A B C
# |---| |---| |---|
# AA AB BA BB CA CB
# |----| |----|
# AAA AAB BBA BBB
# Names of the bottom level variables
data_bts <- data.frame(X1 = c("A", "A", "A", "B", "B", "B", "C", "C"),
X2 = c("A", "A", "B", "A", "B", "B", "A", "B"),
X3 = c("A", "B", NA, NA, "A", "B", NA, NA),
stringsAsFactors = FALSE)
# Cross-sectional aggregation matrix
agg_mat <- df2aggmat(~ X1 / X2 / X3, data_bts, sep = "", verbose = FALSE)
## Group of two hierarchies
# T T T | A | B | C
# |--|--| X |---| -> ---+----+----+----
# A B C M F M | AM | BM | CM
# F | AF | BF | CF
# Names of the bottom level variables
data_bts <- data.frame(X1 = c("A", "A", "B", "B", "C", "C"),
Y1 = c("M", "F", "M", "F", "M", "F"),
stringsAsFactors = FALSE)
# Cross-sectional aggregation matrix
agg_mat <- df2aggmat(~ Y1 * X1, data_bts, sep = "", verbose = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.