Skip to content

Commit

Permalink
deleted type = "exact"
Browse files Browse the repository at this point in the history
  • Loading branch information
qddyy committed Jul 10, 2024
1 parent 496cd3f commit fbe2f52
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 44 deletions.
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,13 @@ importFrom(graphics,layout)
importFrom(graphics,mtext)
importFrom(graphics,par)
importFrom(stats,dbinom)
importFrom(stats,dwilcox)
importFrom(stats,pbinom)
importFrom(stats,pchisq)
importFrom(stats,pf)
importFrom(stats,plot.stepfun)
importFrom(stats,pnorm)
importFrom(stats,pt)
importFrom(stats,ptukey)
importFrom(stats,pwilcox)
importFrom(stats,qnorm)
importFrom(stats,quantile)
importFrom(stats,stepfun)
Expand Down
2 changes: 1 addition & 1 deletion R/SiegelTukey.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ SiegelTukey <- R6Class(
#'
#' @return A `SiegelTukey` object.
initialize = function(
type = c("permu", "asymp", "exact"),
type = c("permu", "asymp"),
alternative = c("two_sided", "less", "greater"),
n_permu = 1e4, correct = TRUE
) {
Expand Down
22 changes: 7 additions & 15 deletions R/Sign.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Sign <- R6Class(
#'
#' @return A `Sign` object.
initialize = function(
type = c("permu", "asymp", "exact"),
type = c("permu", "asymp"),
alternative = c("two_sided", "less", "greater"),
n_permu = 1e4, correct = TRUE
) {
Expand All @@ -43,21 +43,13 @@ Sign <- R6Class(
.calculate_p = function() {
n <- nrow(private$.data)

if (private$.type == "exact") {
private$.p_value <- get_p_binom(
private$.statistic, n, 0.5, private$.side
)
}

if (private$.type == "asymp") {
z <- private$.statistic - n / 2
correction <- if (private$.correct) {
switch(private$.side, lr = sign(z) * 0.5, r = 0.5, l = -0.5)
} else 0
z <- (z - correction) / sqrt(n / 4)
z <- private$.statistic - n / 2
correction <- if (private$.correct) {
switch(private$.side, lr = sign(z) * 0.5, r = 0.5, l = -0.5)
} else 0
z <- (z - correction) / sqrt(n / 4)

private$.p_value <- get_p_continous(z, "norm", private$.side)
}
private$.p_value <- get_p_continous(z, "norm", private$.side)
}
),
active = list(
Expand Down
33 changes: 11 additions & 22 deletions R/Wilcoxon.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' @export
#'
#' @importFrom R6 R6Class
#' @importFrom stats pnorm qnorm pwilcox dwilcox
#' @importFrom stats pnorm qnorm


Wilcoxon <- R6Class(
Expand All @@ -22,7 +22,7 @@ Wilcoxon <- R6Class(
#'
#' @return A `Wilcoxon` object.
initialize = function(
type = c("permu", "asymp", "exact"),
type = c("permu", "asymp"),
alternative = c("two_sided", "less", "greater"),
null_value = 0, conf_level = 0.95,
n_permu = 1e4, correct = TRUE
Expand Down Expand Up @@ -50,6 +50,7 @@ Wilcoxon <- R6Class(
.calculate_p = function() {
m <- length(private$.data$x)
n <- length(private$.data$y)
N <- m + n

statistic <- private$.statistic - m * (m + 1) / 2

Expand All @@ -59,27 +60,15 @@ Wilcoxon <- R6Class(
private$.type <- "asymp"
}

if (private$.type == "exact") {
private$.p_value <- get_p_decrete(
statistic, "wilcox", private$.side, m = m, n = n
)
}

if (private$.type == "asymp") {
N <- m + n

z <- statistic - m * n / 2
correction <- if (private$.correct) {
switch(private$.side, lr = sign(z) * 0.5, r = 0.5, l = -0.5)
} else 0
z <- (z - correction) / sqrt(
m * n / 12 * (
N + 1 - sum(ties^3 - ties) / (N * (N - 1))
)
)
z <- statistic - m * n / 2
correction <- if (private$.correct) {
switch(private$.side, lr = sign(z) * 0.5, r = 0.5, l = -0.5)
} else 0
z <- (z - correction) / sqrt(
m * n / 12 * (N + 1 - sum(ties^3 - ties) / (N * (N - 1)))
)

private$.p_value <- get_p_continous(z, "norm", private$.side)
}
private$.p_value <- get_p_continous(z, "norm", private$.side)
},

.calculate_extra = function() {
Expand Down
2 changes: 1 addition & 1 deletion man/SiegelTukey.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/Sign.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/Wilcoxon.Rd

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

2 changes: 1 addition & 1 deletion vignettes/examples.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ t$p_value
```{r}
# See ?Sign or ?paired.sign
t <- pmt(
"paired.sign", alternative = "greater", type = "exact"
"paired.sign", alternative = "greater", n_permu = 0
)
t$test(
Expand Down

0 comments on commit fbe2f52

Please sign in to comment.