Skip to content

Commit

Permalink
Ready for CRAN
Browse files Browse the repository at this point in the history
  • Loading branch information
marberts committed Nov 14, 2023
1 parent 5d2f66d commit 7cdb54e
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion 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.5.0.9009
Version: 0.6.0
Authors@R: c(
person("Steve", "Martin", role = c("aut", "cre", "cph"),
email = "[email protected]",
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ control whether products in the first period match to themselves or return `NA`.

- Updated documentation.

- Added a vignette.
- Added a brief vignette.

## Version 0.5.0

Expand Down
2 changes: 1 addition & 1 deletion R/offset_prices.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ offset_period <- function(f) {
#' gives the location of the corresponding product in the previous period.
#' With `base_period()`, the resulting vector gives the location of the
#' corresponding product in the first period. The locations are unchanged for
#' he first time period if `match_first = TRUE`, `NA` otherwise.
#' the first time period if `match_first = TRUE`, `NA` otherwise.
#'
#' @note
#' By definition, there must be at most one transaction for each product
Expand Down
18 changes: 14 additions & 4 deletions R/outliers.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Outlier methods for price relatives
#' Outlier detection for price relatives
#'
#' Standard cutoff-based methods for detecting outliers with price relatives.
#'
Expand Down Expand Up @@ -89,13 +89,15 @@
#' @export
quartile_method <- function(x, cu = 2.5, cl = cu, a = 0, type = 7) {
x <- as.numeric(x)
cu <- as.numeric(cu)
cl <- as.numeric(cl)
q <- stats::quantile(
x, c(0.25, 0.5, 0.75),
names = FALSE, na.rm = TRUE, type = type
)
x <- x - q[2L]
u <- cu * pmax(q[3L] - q[2L], abs(a * q[2L]))
l <- -cl * pmax(q[2L] - q[1L], abs(a * q[2L]))
u <- cu * pmax.int(q[3L] - q[2L], abs(a * q[2L]))
l <- -cl * pmax.int(q[2L] - q[1L], abs(a * q[2L]))
x > u | x < l
}

Expand All @@ -104,11 +106,13 @@ quartile_method <- function(x, cu = 2.5, cl = cu, a = 0, type = 7) {
#' @export
resistant_fences <- function(x, cu = 2.5, cl = cu, a = 0, type = 7) {
x <- as.numeric(x)
cu <- as.numeric(cu)
cl <- as.numeric(cl)
q <- stats::quantile(
x, c(0.25, 0.5, 0.75),
names = FALSE, na.rm = TRUE, type = type
)
iqr <- pmax(q[3L] - q[1L], abs(a * q[2L]))
iqr <- pmax.int(q[3L] - q[1L], abs(a * q[2L]))
u <- q[3L] + cu * iqr
l <- q[1L] - cl * iqr
x > u | x < l
Expand All @@ -119,6 +123,8 @@ resistant_fences <- function(x, cu = 2.5, cl = cu, a = 0, type = 7) {
#' @export
robust_z <- function(x, cu = 2.5, cl = cu) {
x <- as.numeric(x)
cu <- as.numeric(cu)
cl <- as.numeric(cl)
med <- stats::median(x, na.rm = TRUE)
s <- stats::mad(x, na.rm = TRUE)
x <- x - med
Expand All @@ -132,6 +138,8 @@ robust_z <- function(x, cu = 2.5, cl = cu) {
#' @export
fixed_cutoff <- function(x, cu = 2.5, cl = 1 / cu) {
x <- as.numeric(x)
cu <- as.numeric(cu)
cl <- as.numeric(cl)
x > cu | x < cl
}

Expand All @@ -140,6 +148,8 @@ fixed_cutoff <- function(x, cu = 2.5, cl = 1 / cu) {
#' @export
tukey_algorithm <- function(x, cu = 2.5, cl = cu, type = 7) {
x <- as.numeric(x)
cu <- as.numeric(cu)
cl <- as.numeric(cl)
q <- stats::quantile(
x, c(0.05, 0.95),
names = FALSE, na.rm = TRUE, type = type
Expand Down
6 changes: 2 additions & 4 deletions R/weights.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
#' `nested_transmute(r1, r2, t, s)` and `nested_transmute2(r1, r2, t, s)` do
#' the same for nested generalized means, so that
#'
#' \preformatted{
#' nested_mean(r1, r2, t)(x, w1, w2) ==
#' generalized_mean(s)(x, v(x, w1, w2))
#' }
#' \preformatted{nested_mean(r1, r2, t)(x, w1, w2) ==
#' generalized_mean(s)(x, v(x, w1, w2))}
#'
#' This generalizes the result for turning a geometric mean into an arithmetic
#' mean (and vice versa) in section 4.2 of Balk (2008), and a Fisher mean into
Expand Down
2 changes: 1 addition & 1 deletion man/back_period.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/outliers.Rd

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

6 changes: 2 additions & 4 deletions man/transmute_weights.Rd

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

2 changes: 1 addition & 1 deletion tests/Examples/gpindex-Ex.Rout.save
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ Warning in back_period(period) :
> flush(stderr()); flush(stdout())
>
> ### Name: outliers
> ### Title: Outlier methods for price relatives
> ### Title: Outlier detection for price relatives
> ### Aliases: outliers quartile_method resistant_fences robust_z
> ### fixed_cutoff tukey_algorithm hb_transform
>
Expand Down

0 comments on commit 7cdb54e

Please sign in to comment.