-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
122 lines (89 loc) · 4.61 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file. -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
out.width = "100%"
)
```
# Generalized Price and Quantity Indexes <a href="https://marberts.github.io/gpindex/"><img src="man/figures/logo.png" align="right" height="139" alt="gpindex website" /></a>
<!-- badges: start -->
[![CRAN status](https://www.r-pkg.org/badges/version/gpindex)](https://cran.r-project.org/package=gpindex)
[![gpindex status badge](https://marberts.r-universe.dev/badges/gpindex)](https://marberts.r-universe.dev/gpindex)
[![Conda Version](https://img.shields.io/conda/vn/conda-forge/r-gpindex.svg)](https://anaconda.org/conda-forge/r-gpindex)
[![R-CMD-check](https://github.com/marberts/gpindex/workflows/R-CMD-check/badge.svg)](https://github.com/marberts/gpindex/actions)
[![codecov](https://codecov.io/gh/marberts/gpindex/graph/badge.svg?token=TL7V9QO0BH)](https://app.codecov.io/gh/marberts/gpindex)
[![DOI](https://zenodo.org/badge/261861375.svg)](https://zenodo.org/doi/10.5281/zenodo.10097742)
<!-- badges: end -->
Tools to build and work with bilateral generalized-mean price indexes (and by extension quantity indexes), and indexes composed of generalized-mean indexes (e.g., superlative quadratic-mean indexes, GEKS). Covers the core mathematical machinery for making bilateral price indexes, computing price relatives, detecting outliers, and decomposing indexes, with wrappers for all common (and many uncommon) index-number formulas. Implements and extends many of the methods in Balk (2008), von der Lippe (2007), and the CPI manual (2020).
## Installation
Get the stable release from CRAN.
```{r, eval = FALSE}
install.packages("gpindex")
```
The development version can be installed from R-Universe
```{r, eval = FALSE}
install.packages("gpindex", repos = c("https://marberts.r-universe.dev", "https://cloud.r-project.org"))
```
or directly from GitHub.
```{r, eval = FALSE}
pak::pak("marberts/gpindex")
```
## Usage
```{r}
library(gpindex)
# Start with some data on prices and quantities for 6 products
# over 5 periods
price6
quantity6
# We'll only need prices and quantities for a few periods
p0 <- price6[[1]]
p1 <- price6[[2]]
p2 <- price6[[3]]
q0 <- price6[[1]]
q1 <- price6[[2]]
# There are functions to calculate all common price indexes,
# like the Laspeyres and Paasche index
laspeyres_index(p1, p0, q0)
paasche_index(p1, p0, q1)
# The underlying mean functions are also available, as usually
# only price relatives and weights are known
s0 <- p0 * q0
s1 <- p1 * q1
arithmetic_mean(p1 / p0, s0)
harmonic_mean(p1 / p0, s1)
# The mean representation of a Laspeyres index makes it easy to
# chain by price-updating the weights
laspeyres_index(p2, p0, q0)
arithmetic_mean(p1 / p0, s0) *
arithmetic_mean(p2 / p1, update_weights(p1 / p0, s0))
# The mean representation of a Paasche index makes it easy to
# calculate percent-change contributions
harmonic_contributions(p1 / p0, s1)
# The ideas are the same for more exotic indexes,
# like the Lloyd-Moulton index
# Let's start by making some functions for the Lloyd-Moulton index
# when the elasticity of substitution is -1 (an output index)
lloyd_moulton <- lm_index(-1)
quadratic_mean <- generalized_mean(2)
quadratic_update <- factor_weights(2)
quadratic_contributions <- contributions(2)
# This index can be calculated as a mean of price relatives
lloyd_moulton(p1, p0, q0)
quadratic_mean(p1 / p0, s0)
# Chained over time
lloyd_moulton(p2, p0, q0)
quadratic_mean(p1 / p0, s0) *
quadratic_mean(p2 / p1, quadratic_update(p1 / p0, s0))
# And decomposed to get the contributions of each relative
quadratic_contributions(p1 / p0, s0)
```
## Prior work
There are a number of R packages on the CRAN that implement the standard index-number formulas (e.g., **IndexNumber**, **productivity**, **IndexNumR**, **micEconIndex**, **PriceIndices**). While there is support for a large number of index-number formulas out-of-the box in this package, the focus is on the tools to easily make and work with any type of generalized-mean price index. Consequently, compared to existing packages, this package is suitable for building custom price/quantity indexes, calculating indexes with sample data, decomposing indexes, and learning about or researching different types of index-number formulas.
## References
Balk, B. M. (2008). *Price and Quantity Index Numbers*. Cambridge University Press.
IMF, ILO, Eurostat, UNECE, OECD, and World Bank. (2020). *Consumer Price Index Manual: Concepts and Methods*. International Monetary Fund.
von der Lippe, P. (2007). *Index Theory and Price Statistics*. Peter Lang.