Skip to content

Commit

Permalink
fixed get_data_from & SiegelTukey
Browse files Browse the repository at this point in the history
  • Loading branch information
qddyy committed Sep 14, 2023
1 parent 6b19987 commit 989efe3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
23 changes: 12 additions & 11 deletions R/SiegelTukey.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ SiegelTukey <- R6Class(
private$.adjust_median <- adjust_median

super$initialize(...)

private$.scoring <- "siegel-tukey rank"
}
),
private = list(
Expand All @@ -41,15 +39,16 @@ SiegelTukey <- R6Class(
.calculate_extra = function() {},

.calculate_score = function() {
x <- private$.data$x
y <- private$.data$y

if (private$.adjust_median) {
x <- x - median(x)
y <- y - median(y)
private$.data <- lapply(
private$.data, function(x) x - median(x)
)
}

c_xy <- c(x, y)
super$.calculate_score()
private$.scoring <- "siegel-tukey rank"

c_xy <- c(private$.data$x, private$.data$y)
N <- length(c_xy)

rank_l <- outer(c(1, 4), seq.int(from = 0, to = N - 1, by = 4), "+")
Expand All @@ -66,11 +65,13 @@ SiegelTukey <- R6Class(
}

st_rank <- vapply(
X = split(c(rank_l, rev(rank_r)), sort(c_xy)),
FUN = mean, FUN.VALUE = numeric(1)
X = split(c(rank_l, rev(rank_r)), seq_len(N)),
FUN = mean, FUN.VALUE = numeric(1), USE.NAMES = FALSE
)

private$.data <- list(x = st_rank[as.character(x)], y = st_rank[as.character(y)])
private$.data <- lapply(
private$.data, function(x) st_rank[x]
)
}
)
)
6 changes: 4 additions & 2 deletions R/TwoSampleTest.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ TwoSampleTest <- R6Class(
},

.calculate_score = function() {
scores <- get_score(c(private$.data$x, private$.data$y), method = private$.scoring)
score <- 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])
private$.data <- list(x = score[x_index], y = score[-x_index])
},

.calculate_statistic = function() {
Expand Down
2 changes: 1 addition & 1 deletion R/auxiliary_funcs.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ get_data_from <- function(...) {
if (length(data) == 1 & is.list(data[[1]])) {
data <- data[[1]]
}
if (all(vapply(data, length, numeric(1)) >= 2)) data
if (all(vapply(data, length, numeric(1)) >= 2)) as.list(data)
}

# for .calculate_score
Expand Down

0 comments on commit 989efe3

Please sign in to comment.