# nested_contributions: Nested contributions In gpindex: Generalized Price and Quantity Indexes

## Description

Calculate additive quote contributions for a price index that nests two levels of generalized means, like the Fisher index, consisting of an outer generalized mean and an collection of inner generalized means.

## Usage

 `1` ```contributions_nested(r1, r2, w1 = rep(1, length(r2))) ```

## Arguments

 `r1` A finite number giving the order of the outer generalized mean. `r2` A vector of finite numbers giving the order of the inner generalized means. `w1` A vector of numeric weights that weights each inner generalized mean in the outer generalized mean, the same length as `r2`.

## Details

This function is the analog of `contributions()` for a nested generalized mean with two levels, like a Fisher or Harmonic Laspeyres Paasche index. That is, it calculates the contribution of each element of `x` when a generalized mean of order `r1`, with weights `w1`, aggregates a collection of generalized means of `x` with orders in the list `r2`, each with weights in the list `w`.

## Value

`contributions_nested()` returns a function:

`function(x, w = rep(list(rep(1, length(x))), length(r2)))`.

This function takes a numeric vector `x` and list of numeric weights `w`, the same length as `r2`, and returns the contribution for each element in `x`.

## Note

This function is experimental, and the interface may change in future versions.

`contributions` for contributions without nesting.
 ``` 1 2 3 4 5 6 7 8 9 10 11 12``` ```p1 <- price6[[2]] p0 <- price6[[1]] q1 <- quantity6[[2]] q0 <- quantity6[[1]] contributions_fisher <- contributions_nested(0, c(1, -1)) contributions_fisher(p1 / p0, list(index_weights("Laspeyres")(p0, q0), index_weights("Paasche")(p1, q1))) contributions_hlp <- contributions_nested(-1, c(1, -1)) contributions_hlp(p1 / p0, list(index_weights("Laspeyres")(p0, q0), index_weights("Paasche")(p1, q1))) ```