Skip to content

Commit

Permalink
Added r to geks()
Browse files Browse the repository at this point in the history
  • Loading branch information
marberts committed Feb 10, 2024
1 parent 0a002ce commit 85a744c
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 20 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: gpindex
Title: Generalized Price and Quantity Indexes
Version: 0.6.0.9008
Version: 0.6.0.9009
Authors@R: c(
person("Steve", "Martin", role = c("aut", "cre", "cph"),
email = "[email protected]",
Expand All @@ -11,7 +11,7 @@ Description: Tools to build and work with bilateral generalized-mean
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 wrapper for all common (and many uncommon) index-number
with wrappers for all common (and many uncommon) index-number
formulas. Implements and extends many of the methods in
Balk (2008, ISBN:978-1-107-40496-0),
von der Lippe (2001, ISBN:3-8246-0638-0), and the
Expand All @@ -33,4 +33,4 @@ Collate: 'helpers.R' 'means.R' 'weights.R' 'contributions.R' 'price_indexes.R'
Config/testthat/edition: 3
VignetteBuilder: knitr
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

- Updated maintainer email.

- Added a parameter to generalize `geks()` by controlling how indexes are
averaged over the rolling window.

## Version 0.6.0

- Bumped minimum version of R to at least 4.0.
Expand Down
19 changes: 11 additions & 8 deletions R/geks.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,16 @@ geks_matrix <- function(index, p, q, product, n, nper, window, na.rm) {

#' GEKS index
#'
#' Calculate an inter-temporal GEKS price index over a rolling window, as
#' described in chapter 7 of Balk (2008), by Ivancic et al. (2011), and in
#' chapter 10 of the CPI manual (2020).
#' Calculate a generalized inter-temporal GEKS price index over a rolling
#' window, as described in chapter 7 of Balk (2008), by Ivancic et al. (2011),
#' and in chapter 10 of the CPI manual (2020).
#'
#' @param f A [price index function][price_indexes] that uses information on both
#' base and current-period prices and quantities, and satisfies the
#' @param f A [price index function][price_indexes] that uses information on
#' both base and current-period prices and quantities, and satisfies the
#' time-reversal test. Usually a Törnqvist, Fisher, or Walsh index.
#' @param r A finite number giving the order of the generalized mean used to
#' average price indexes over the rolling window. The default uses a
#' geometric mean.
#' @param p A numeric vector of prices, the same length as `q`.
#' @param q A numeric vector of quantities, the same length as `p`.
#' @param period A factor, or something that can be coerced into one, that
Expand Down Expand Up @@ -158,9 +161,9 @@ geks_matrix <- function(index, p, q, product, n, nper, window, na.rm) {
#'
#' @family price-indexes
#' @export
geks <- function(f) {
geks <- function(f, r = 0) {
f <- match.fun(f)

gen_mean <- generalized_mean(r)
function(p, q, period, product,
window = nlevels(period), n = window - 1L, na.rm = FALSE) {
if (different_lengths(p, q, period, product)) {
Expand Down Expand Up @@ -211,7 +214,7 @@ geks <- function(f) {
for (i in seq_along(res)) {
index <- apply(
mat[rows + i, cols + i, drop = FALSE], 2L,
geometric_mean,
gen_mean,
na.rm = na.rm
)
res[[i]] <- index[-1L] / index[-length(index)]
Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ knitr::opts_chunk$set(
[![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 wrapper for all common (and many uncommon) index-number formulas. Implements and extends many of the methods in Balk (2008), von der Lippe (2001), and the CPI manual (2020).
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 (2001), and the CPI manual (2020).

## Installation

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Tools to build and work with bilateral generalized-mean price indexes
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 wrapper for all common (and many uncommon) index-number
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 (2001), and the CPI manual (2020).

Expand Down
16 changes: 10 additions & 6 deletions man/geks.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/gpindex-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 85a744c

Please sign in to comment.