-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
98 lines (65 loc) · 3.23 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
---
output:
md_document:
variant: markdown_github
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "images/README-"
)
```
# GEKS-Törnqvist Decomposition
This package focuses on one function `GEKSdecomp`, which decomposes the multilateral GEKS-Tornqvist index into the contributions of individual commodities. The calculation is based purely on the *Decomposing Multilateral Price Indexes into the Contributions of Individual Commodities* paper written by *Michael Webster* and *Rory C. Tarnow-Mordi*. It uses the techinque
described under section [2.2 Decomposition of the CCD and GEKS Methods](https://www.researchgate.net/publication/333875150_Decomposing_Multilateral_Price_Indexes_into_the_Contributions_of_Individual_Commodities).
This package should be coupled with the [GEKS package](https://github.com/MjStansfi/GEKS_package). Also see the alternates available for the FEWS (time product dummy) multilateral method [FEWS package](https://github.com/MjStansfi/FEWS_package) and
[TPD decomposition](https://github.com/MjStansfi/TPDDecomp).
See the attached pdf, [GEKS proofs](https://github.com/MjStansfi/GEKSdecomp/blob/master/GEKS_proofs.pdf) to understand how the code was simplified for conditions where either price a or b is missing.
# Installation
The GEKS decomposition function can be installed from GitHub using the following code
```{undefined eval=FALSE, include=TRUE}
devtools::install_github("MjStansfi/GEKSdecomp")
```
```{r}
# Once installed, the package can be loaded as usual
library(GEKSdecomp)
```
# Usage
The primary function provided by the the package is the `GEKS_decomp()` function. Running `?GEKS_decomp()` will give all the required information on how to use the function. An example of running the `GEKS_decomp()` the function is shown below.
# Example
This pacakge includes the Turvey dataset as found in the [Consumer Price Index Manual](https://www.ilo.org/wcmsp5/groups/public/---dgreports/---stat/documents/presentation/wcms_331153.pdf).
```{r, turvey-overview}
library(ggplot2)
ggplot(turvey, aes(x = month, y = price)) +
geom_line(aes(color = commodity)) +
geom_point(aes(color = commodity))+
theme_bw() +
ggtitle("Artificial prices of seasonal products Data created by R. Turvey")+
annotate("rect", xmin=as.Date("1973-04-30"), xmax=as.Date("1973-05-31"), ymin=0, ymax=10,
alpha = .5)
```
The decomposition of the Turvey dataset with the contributions between 1973-04-30 and 1973-05-31 can be seen below.
``` {r}
#Make sure you restart your session if just installed
str(turvey)
contributions <- with(
turvey,
GEKS_decomp(times = month,
price = price,
id = commodity,
weight = price*quantity,
custom_time = c("1973-04-30","1973-05-31"),
window_length = NULL)
)
print(contributions)
```
```{r percentage_contrib, echo=FALSE}
ggplot(contributions)+
geom_bar(aes(x=id,y=p_contrib), stat = "identity")+
coord_flip()+
ggtitle("Percentage contribution of observation")+
geom_label(aes(x=id,y=p_contrib,label=paste0(round(p_contrib*100,1),"%")))+
xlab("Product")+ylab("Percentage contribution")
```