The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.
Price indexes are often aggregated over multiple hierarchical dimensions. Industry indexes that use, say, 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. An industry-based index can also form the basis for a product-based index, or vice versa. In both cases, an index is re-aggregated to produce indexes for new dimensions that aren’t part of the original aggregation structure.
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
#> 1 B1 11 553 1 11 TS
#> 2 B2 11 646 1 11 TA
#> 3 B3 11 312 1 11 TS
#> 4 B4 12 622 1 12 TS
#> 5 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 combine_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
Rather aggregating over multiple dimensions within a combined hierarchical classification,
in some cases an index is re-aggregated over a different classification by means of
a concordance between the elementary aggregates. Continuing with the previous example,
suppose industry 11 produce products a and b, and industry 12 produce products b and c, with the following weights.
product_weights <- data.frame(
product = c("a", "b", "b", "c"),
industry = c("11", "11", "12", "12"),
weight = 1:4
)
product_pias <- aggregation_structure(
combine_classifications(
list(product_weights$product),
list(product_weights$industry)
),
product_weights$weight
)
product_pias
#> Aggregation structure for 4 elementary aggregates with 1 levels above the elementary aggregates
#> level1 ea weight
#> 1 a a.11 1
#> 2 b b.11 2
#> 3 b b.12 3
#> 4 c c.12 4
The industry-based index can be expanded and re-aggregated to make a product-based index. The key to doing so is to construct a concordance between industries and products.
concord <- setNames(product_weights$industry, levels(product_pias)$ea)
concord
#> a.11 b.11 b.12 c.12
#> "11" "11" "12" "12"
This concordance can be used to expand the industry index and re-aggregate it with the product-based aggregation structure.
aggregate(index_sps[concord], product_pias)
#> Period-over-period price index for 7 levels over 4 time periods
#> time
#> levels 202001 202002 202003 202004
#> a 1 1.300724 1.063074 1.492443
#> b 1 1.300724 1.063074 3.342749
#> c 1 1.300724 1.063074 4.576286
#> a.11 1 1.300724 1.063074 1.492443
#> b.11 1 1.300724 1.063074 1.492443
#> b.12 1 1.300724 1.063074 4.576286
#> c.12 1 1.300724 1.063074 4.576286
These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.