Skip to content

Commit

Permalink
Merge branch 'hyndman-suggestions' into develop
Browse files Browse the repository at this point in the history
* hyndman-suggestions:
  Updated NEWS.md
  Refactoring
  Increment version number to 1.0.0.9001
  Added TODOs
  Updated docs
  Implemented faster `chackoStatistic()`
  Improved validation of `x`
  • Loading branch information
wleoncio committed Sep 5, 2024
2 parents ccb2cee + bc0c9b2 commit 2852721
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: permChacko
Title: Chacko Test for Order-Restriction with Permutation
Version: 1.0.0.9000
Version: 1.0.0.9001
Date: 2024-04-17
Authors@R:
c(
Expand All @@ -25,7 +25,8 @@ Description: Implements an extension of the Chacko chi-square test for
License: GPL (>= 3)
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Imports: methods
Suggests:
knitr,
rmarkdown,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ export(chacko66_sec5)
export(permChacko)
export(reduceVector)
export(ruxton221207)
importFrom(methods,is)
importFrom(stats,pchisq)
importFrom(stats,weighted.mean)
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# permChacko (development version)

* Improved validation
* Optimized `chackoStatistic()`

# permChacko 1.0.0

* Improved printing of hypothesis ([issue #11](https://github.com/ocbe-uio/permChacko/issues/11)).
Expand Down
16 changes: 7 additions & 9 deletions R/chackoStatistic.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
chackoStatistic <- function(x_t, n, k) {
x_bar <- x_t[, "x"]
t <- x_t[, "t"]
m <- length(unique(x_bar))
power_sum <- 0
for (j in seq_len(m)) {
power_sum <- power_sum + t[[j]] * (x_bar[[j]] - n / k) ^ 2
}
return(k / n * power_sum)
chackoStatistic <- function(x_t, n, k, uniqueness_method = 1) {
m <- length(unique(x_t[, "x"])) # TODO: check what Chacko really means by m
x_t_unique <- switch(uniqueness_method,
x_t[seq_len(m), , drop = FALSE], # current implementation
x_t[!duplicated(x_t[, "x"]), , drop = FALSE], # new idea (hidden)
)
k / n * sum(x_t_unique[, "t"] * (x_t_unique[, "x"] - n / k) ^ 2)
}
5 changes: 1 addition & 4 deletions R/permChacko-package.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#' @keywords internal
#' @aliases permChacko-package
#' @importFrom methods is
"_PACKAGE"

## usethis namespace: start
## usethis namespace: end
NULL
2 changes: 1 addition & 1 deletion R/permChacko.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#' permChacko(chacko66_sec5)
#' @export
permChacko <- function(x, n_perm = 1000L, verbosity = 0) {
if (!is.null(dim(x))) stop("Input must be a vector")
if (!is(x, "numeric")) stop("Input must be a vector")
if (verbosity >= 1L) message("Reducing original vector")
# Ordering and reducing vector
x_t <- reduceVector(x, verbosity)[["x_t"]]
Expand Down
2 changes: 1 addition & 1 deletion R/reduceVector.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#' reduceVector(chacko66_sec5)
#' reduceVector(chacko66_sec5, verbosity = 1)
reduceVector <- function(x, verbosity = 0L) {
if (!is.null(dim(x))) stop("Input must be a vector")
if (!is(x, "numeric")) stop("Input must be a vector")
x_t <- cbind("x" = unname(x), "t" = unname(x) ^ 0L)
reductions <- 0L
while (nrow(x_t) > 1L && isMonotoneIncreasing(x_t[, "x"])) {
Expand Down

0 comments on commit 2852721

Please sign in to comment.