Example with R: Index-number formulas

All of the index-number formulas presented in this section are simply weighted averages, and are fairly easy to calculate in R given information on prices and some weights.

# Bring in gpindex library
library(gpindex) # install.packages("gpindex")

# Make some price relatives
relatives <- c(1.1, 1.2, 0.9, 1.1)

# Make some weights
weights <- c(0.25, 0.3, 0.3, 0.15)

# Calculate indices
c(Carli = arithmetic_mean(relatives), 
  Jevons = geometric_mean(relatives), 
  Arithmetic = arithmetic_mean(relatives, weights),
  Geometric = geometric_mean(relatives, weights))
##      Carli     Jevons Arithmetic  Geometric 
##   1.075000   1.069184   1.070000   1.063125

The type of arithmetic and geometric indices that this calculates depends entirely on how the weights are calculated. Usually, weights come from data on expenditure/revenue shares, and how this information is used to weight price relatives will affect the type of price index that is calculated.

# Base-period expenditure/revenue share
share0 <- c(0.25, 0.3, 0.3, 0.15) 

# Current-period expenditure/revenue share
share1 <- c(0.2, 0.2, 0.4, 0.2)

# Calculate indices
c(Laspeyres = arithmetic_mean(relatives, share0),
  Paasche = harmonic_mean(relatives, share1),
  Fisher = sqrt(arithmetic_mean(relatives, share0) *
                  harmonic_mean(relatives, share1)),
  `Geometric Laspeyres` = geometric_mean(relatives, share0),
  `Geometric Paasche` = geometric_mean(relatives, share1),
  Tornqvist = geometric_mean(relatives, (share0 + share1) / 2))
##           Laspeyres             Paasche              Fisher Geometric Laspeyres 
##            1.070000            1.025907            1.047721            1.063125 
##   Geometric Paasche           Tornqvist 
##            1.032976            1.047942

It is interesting to note that any geometric index can be turned into an arithmetic index by an appropriate change of weights. This gives an easy way to determine the contribution that each price relative has towards the index value.

# Tornqvist index
geometric_mean(relatives, (share0 + share1) / 2) 
## [1] 1.047942
# Change the weights
new_weights <- transmute_weights(0, 1)(relatives, (share0 + share1) / 2)
arithmetic_mean(relatives, new_weights) # same as geometric mean
## [1] 1.047942
# Contribution of each relative
(relatives - 1) * new_weights
## [1]  0.02095439  0.04455317 -0.03600469  0.01629786