# A simple aggregation structure
# 1
# |-----+-----|
# 11 12
# |---+---| |
# 111 112 121
# (1) (3) (4)
aggregation_weights <- data.frame(
level1 = c("1", "1", "1"),
level2 = c("11", "11", "12"),
ea = c("111", "112", "121"),
weight = c(1, 3, 4)
)
pias <- as_aggregation_structure(aggregation_weights)
as.matrix(pias)
all.equal(as.data.frame(pias), aggregation_weights)
if (FALSE) {
# Visualize as a treemap.
treemap::treemap(
aggregation_weights,
index = names(aggregation_weights)[-4],
vSize = "weight",
title = "aggregation structure"
)
# Or turn into a more genereal tree object and plot.
aggregation_weights$pathString <- do.call(
\(...) paste(..., sep = "/"),
aggregation_weights[-4]
)
plot(data.tree::as.Node(aggregation_weights))
}
Run the code above in your browser using DataLab