p1 <- price6[[2]]
p2 <- price6[[3]]
q1 <- quantity6[[2]]
q2 <- quantity6[[3]]
# Most indexes can be calculated by combining the appropriate weights
# with the correct type of mean.
laspeyres_index(p2, p1, q1)
arithmetic_mean(p2 / p1, index_weights("Laspeyres")(p1, q1))
geometric_index("Laspeyres")(p2, p1, q1)
geometric_mean(p2 / p1, index_weights("Laspeyres")(p1, q1))
# NAs get special treatment.
p_na <- replace(p1, 6, NA)
laspeyres_index(p2, p_na, q1, na.rm = TRUE) # drops the last price relative
sum(p2 * q1, na.rm = TRUE) /
sum(p_na * q1, na.rm = TRUE) # drops the last period-0 price
# von Bortkiewicz decomposition
paasche_index(p2, p1, q2) / laspeyres_index(p2, p1, q1) - 1
wl <- scale_weights(index_weights("Laspeyres")(p1, q1))
pl <- laspeyres_index(p2, p1, q1)
ql <- quantity_index(laspeyres_index)(q2, q1, p1)
sum(wl * (p2 / p1 / pl - 1) * (q2 / q1 / ql - 1))
# Similar decomposition for geometric Laspeyres/Paasche.
wp <- scale_weights(index_weights("Paasche")(p2, q2))
gl <- geometric_index("Laspeyres")(p2, p1, q1)
gp <- geometric_index("Paasche")(p2, p1, q2)
log(gp / gl)
sum(scale_weights(wl) * (wp / wl - 1) * log(p2 / p1 / gl))
Run the code above in your browser using DataLab