Aggregating across dimensions

Price indexes are often aggregated over multiple hierarchical dimensions. Matched sample indexes that use sequential Poisson sampling to draw a sample of businesses are a good example, as there are usually take-all and take-some strata in addition to, say, an industry classification.

Let’s extend vignette("piar") by adding another dimension to the classification to say if a business belongs to the take-all or take-some sampling stratum.

library(piar)

elementals <- ms_prices |>
  transform(
    relative = price_relative(price, period = period, product = product)
  ) |>
  elementary_index(relative ~ period + business, na.rm = TRUE)
ms_weights$stratum <- c("TS", "TA", "TS", "TS", "TS")

ms_weights
business classification weight level1 level2 stratum
B1 11 553 1 11 TS
B2 11 646 1 11 TA
B3 11 312 1 11 TS
B4 12 622 1 12 TS
B5 12 330 1 12 TS

The easiest way to deal with multiple digit-wise classifications is to concatenate them into one classification with the combined_classifications() function. In this example the “stratum” dimension comes before the “classification” dimension for the purposes of overall-mean imputation.

classification_sps <- combine_classifications(
  expand_classification(ms_weights$classification),
  list(ms_weights$stratum)
)

pias_sps <- aggregation_structure(
  c(classification_sps, list(ms_weights$business)),
  ms_weights$weight
)

pias_sps
#> Aggregation structure for 5 elementary aggregates with 3 levels above the elementary aggregates 
#>   level1 level2 level3 ea weight
#> 1      1     11  11.TS B1    553
#> 2      1     11  11.TA B2    646
#> 3      1     11  11.TS B3    312
#> 4      1     12  12.TS B4    622
#> 5      1     12  12.TS B5    330

The elementary indexes can now be aggregated according to this new aggregation structure.

index_sps <- aggregate(elementals, pias_sps, na.rm = TRUE)

index_sps
#> Period-over-period price index for 11 levels over 4 time periods 
#>        time
#> levels  202001    202002    202003   202004
#>   1          1 1.3007239 1.0630743 2.684412
#>   11         1 1.3007239 1.0630743 1.492443
#>   12         1 1.3007239 1.0630743 4.576286
#>   11.TS      1 1.3007239 1.0630743 0.537996
#>   11.TA      1 1.3007239 1.0630743 2.770456
#>   12.TS      1 1.3007239 1.0630743 4.576286
#>   B1         1 0.8949097 0.3342939 0.537996
#>   B2         1 1.3007239 1.0630743 2.770456
#>   B3         1 2.0200036 1.6353355 0.537996
#>   B4         1 1.3007239 1.0630743 4.576286
#>   B5         1 1.3007239 1.0630743 4.576286

When a price index has many dimensions (e.g., industry, sampling stratum, region), it can be useful to interact the classifications for these different dimensions to get all possible aggregation structures. The aggregated index can then be re-aggregated to get index values for all dimensions.

Continuing with the example, the industry and strata classifications can be interacted to get two aggregation structures that can be used to re-aggregate index_sps.

interacted_hierarchy <- interact_classifications(
  expand_classification(ms_weights$classification),
  expand_classification(ms_weights$stratum)
)

pias_sps2 <- lapply(
  interacted_hierarchy,
  \(x) aggregation_structure(c(x, list(ms_weights$business)), ms_weights$weight)
)

index_sps2 <- lapply(pias_sps2, \(x) {
  aggregate(index_sps, x, include_ea = FALSE)
})

The resulting indexes can be merged together to give an index that includes all combinations of industry and sampling stratum.

Reduce(merge, index_sps2)
#> Period-over-period price index for 8 levels over 4 time periods 
#>        time
#> levels  202001   202002   202003   202004
#>   1:T        1 1.300724 1.063074 2.684412
#>   1:TS       1 1.300724 1.063074 2.653820
#>   1:TA       1 1.300724 1.063074 2.770456
#>   11:T       1 1.300724 1.063074 1.492443
#>   12:T       1 1.300724 1.063074 4.576286
#>   11:TS      1 1.300724 1.063074 0.537996
#>   11:TA      1 1.300724 1.063074 2.770456
#>   12:TS      1 1.300724 1.063074 4.576286