aggregation_structure {piar}R Documentation

Make a price index aggregation structure

Description

Create a price index aggregation structure from a hierarchical classification and aggregation weights that can be used to aggregate elemental indexes.

Usage

aggregation_structure(x, weights = NULL)

Arguments

x

A list of character vectors that give the codes/labels for each level of the classification, ordered so that moving down the list goes down the hierarchy. The last vector gives the elemental aggregates, which should have no duplicates. All vectors should be the same length, without NAs, and there should be no duplicates across different levels of x.

weights

A numeric vector of aggregation weights for the elemental aggregates (i.e., the last vector in x), or something that can be coerced into one. The default is to give each elemental aggregate the same weight.

Value

A price index aggregation structure of class piar_aggregation_structure. This is a list-S3 class with the following components.

child

A nested list that gives the positions of the immediate children for each node in each level of the aggregation structure above the terminal nodes.

parent

A list that gives the position of the immediate parent for each node of the aggregation structure below the initial nodes.

levels

A list of character vectors that give the levels of x.

weights

A named vector giving the weight for each elemental aggregate.

Warning

The aggregation_structure() function does its best to check its arguments, but there should be no expectation that the result of aggregation_structure() will make any sense if x does not represent a nested hierarchy.

See Also

aggregate() to aggregate price indexes made with elemental_index().

expand_classification() to make x from a character representation of a hierarchical aggregation structure.

as_aggregation_structure() to coerce tabular data into an aggregation structure.

as.data.frame() and as.matrix() to coerce an aggregation structure into a tabular form.

weights() to get the weights for an aggregation structure.

update() for updating a price index aggregation structure with an aggregated index.

Examples

# 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)
)

aggregation_structure(
  aggregation_weights[1:3],
  weights = aggregation_weights[[4]]
)

# The aggregation structure can also be made by expanding the
# elemental aggregates

with(
  aggregation_weights,
  aggregation_structure(expand_classification(ea), weight)
)


[Package piar version 0.7.0 Index]