prices <- data.frame(
rel = 1:8,
period = rep(1:2, each = 4),
ea = rep(letters[1:2], 4)
)
index <- elemental_index(prices, rel ~ period + ea, contrib = TRUE)
pias <- aggregation_structure(
list(c("top", "top", "top"), c("a", "b", "c")), weights = 1:3
)
index <- aggregate(index, pias, na.rm = TRUE)
# Percent-change contributions for the top-level index
contrib(index)
contrib2DF(index)
# Calculate EA contributions for the chained index
library(gpindex)
arithmetic_contributions(
as.matrix(chain(index))[c("a", "b", "c"), 2],
weights(pias)
)
Run the code above in your browser using DataLab