Skip to content

Commit

Permalink
rename some functions
Browse files Browse the repository at this point in the history
  • Loading branch information
qddyy committed Sep 12, 2023
1 parent ab57f15 commit d64585a
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion R/JonckheereTerpstra.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ JonckheereTerpstra <- R6Class(
.name = "Jonckheere-Terpstra Test",

.define_statistic = function() {
k <- as.integer(last(names(private$.data)))
k <- as.integer(get_last(names(private$.data)))
ij <- list(
i = c(lapply(seq_len(k - 1), seq_len), recursive = TRUE),
j = rep.int(seq_len(k)[-1], seq_len(k - 1))
Expand Down
4 changes: 2 additions & 2 deletions R/KSampleTest.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ KSampleTest <- R6Class(
.check = function() {},

.feed = function(...) {
data <- data_to_list(...)
data <- get_data_from(...)

private$.raw_data <- setNames(
c(data, recursive = TRUE, use.names = FALSE),
Expand Down Expand Up @@ -59,7 +59,7 @@ KSampleTest <- R6Class(
},

.calculate_score = function() {
private$.data <- score(private$.data, method = private$.scoring)
private$.data <- get_score(private$.data, method = private$.scoring)
}
)
)
2 changes: 1 addition & 1 deletion R/KruskalWallis.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ KruskalWallis <- R6Class(
},

.calculate_p = function() {
k <- as.integer(last(names(private$.data)))
k <- as.integer(get_last(names(private$.data)))

private$.p_value <- get_p_continous(
private$.statistic, "chisq", "r", df = k - 1
Expand Down
2 changes: 1 addition & 1 deletion R/MultipleComparison.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ MultipleComparison <- R6Class(
},

.define_statistic = function() {
k <- as.integer(last(names(private$.data)))
k <- as.integer(get_last(names(private$.data)))
private$.ij <- ij <- list(
i = rep.int(seq_len(k - 1), seq.int(k - 1, 1)),
j = c(lapply(seq.int(2, k), seq.int, to = k), recursive = TRUE)
Expand Down
4 changes: 2 additions & 2 deletions R/RCBD.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ RCBD <- R6Class(
.check = function() {},

.feed = function(...) {
data <- do.call(data.frame, data_to_list(...))
data <- do.call(data.frame, get_data_from(...))

dim <- dim(data)
rownames(data) <- paste0("treatment_", seq_len(dim[1]))
Expand Down Expand Up @@ -71,7 +71,7 @@ RCBD <- R6Class(
.calculate_score = function() {
private$.data <- do.call(
data.frame, lapply(
X = private$.data, FUN = score,
X = private$.data, FUN = get_score,
method = private$.scoring, n = nrow(private$.data)
)
)
Expand Down
2 changes: 1 addition & 1 deletion R/SignedScore.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ SignedScore <- R6Class(
diff <- diff[diff != 0]
}

private$.score <- score(abs(diff), method = private$.scoring)
private$.score <- get_score(abs(diff), method = private$.scoring)

private$.statistic_func <- function(
swapped, diff_positive = (diff > 0), score = private$.score
Expand Down
4 changes: 2 additions & 2 deletions R/TwoSampleTest.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ TwoSampleTest <- R6Class(
.check = function() {},

.feed = function(...) {
private$.raw_data <- setNames(data_to_list(...), c("x", "y"))
private$.raw_data <- setNames(get_data_from(...), c("x", "y"))
},

.permute = function() {
Expand Down Expand Up @@ -52,7 +52,7 @@ TwoSampleTest <- R6Class(
},

.calculate_score = function() {
scores <- score(c(private$.data$x, private$.data$y), method = private$.scoring)
scores <- get_score(c(private$.data$x, private$.data$y), method = private$.scoring)

x_index <- seq_along(private$.data$x)
private$.data <- list(x = scores[x_index], y = scores[-x_index])
Expand Down
7 changes: 3 additions & 4 deletions R/auxiliary_funcs.R
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
last <- function(x) x[length(x)]
get_last <- function(x) x[length(x)]

# for .feed

data_to_list <- function(...) {
get_data_from <- function(...) {
data <- list(...)

if (length(data) == 1 & is.list(data[[1]])) {
data <- data[[1]]
}

if (all(vapply(data, length, numeric(1)) >= 2)) data
}

# for .calculate_score

score <- function(x, method, n = length(x)) {
get_score <- function(x, method, n = length(x)) {
rank <- rank(x)

switch(method,
Expand Down

0 comments on commit d64585a

Please sign in to comment.