Skip to content

Commit

Permalink
minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
qddyy committed Jan 9, 2024
1 parent a4e58a3 commit 103c393
Show file tree
Hide file tree
Showing 36 changed files with 171 additions and 170 deletions.
File renamed without changes.
6 changes: 3 additions & 3 deletions R/ANOVA.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' @title `r ANOVA$private_fields$.name`
#'
#' @description Performs F statistic based k sample permutation test on data vectors.
#' @description Performs F statistic based k sample permutation test on data vectors.
#'
#' @aliases ksample.anova
#'
Expand All @@ -15,11 +15,11 @@ ANOVA <- R6Class(
inherit = KSampleTest,
cloneable = FALSE,
public = list(
#' @description Create a new `ANOVA` object.
#' @description Create a new `ANOVA` object.
#'
#' @template init_params
#'
#' @return A `ANOVA` object.
#' @return A `ANOVA` object.
initialize = function(
type = c("permu", "asymp"),
n_permu = 0L
Expand Down
6 changes: 3 additions & 3 deletions R/AnsariBradley.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' @title `r AnsariBradley$private_fields$.name`
#'
#' @description Performs two sample Ansari-Bradley test on data vectors.
#' @description Performs two sample Ansari-Bradley test on data vectors.
#'
#' @aliases twosample.ansari
#'
Expand All @@ -15,11 +15,11 @@ AnsariBradley <- R6Class(
inherit = TwoSampleTest,
cloneable = FALSE,
public = list(
#' @description Create a new `AnsariBradley` object.
#' @description Create a new `AnsariBradley` object.
#'
#' @template init_params
#'
#' @return A `AnsariBradley` object.
#' @return A `AnsariBradley` object.
initialize = function(
type = c("permu", "asymp"),
alternative = c("two_sided", "less", "greater"), n_permu = 0L
Expand Down
8 changes: 4 additions & 4 deletions R/CDF.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' @title `r CDF$private_fields$.name`
#'
#' @description Performs statistical inference on population cdf.
#' @description Performs statistical inference on population cdf.
#'
#' @aliases onesample.cdf
#'
Expand All @@ -15,7 +15,7 @@ CDF <- R6Class(
inherit = OneSampleTest,
cloneable = FALSE,
public = list(
#' @description Create a new `CDF` object.
#' @description Create a new `CDF` object.
#'
#' @param conf_level a number specifying confidence level of the confidence bounds.
#'
Expand All @@ -24,11 +24,11 @@ CDF <- R6Class(
super$initialize(conf_level = conf_level)
},

#' @description Plot the estimate and confidence bounds for population cdf of the data.
#' @description Plot the estimate and confidence bounds for population cdf of the data.
#'
#' @template plot_params
#'
#' @return The object itself (invisibly).
#' @return The object itself (invisibly).
plot = function(style = c("graphics", "ggplot2")) {
private$.type <- "permu"
super$plot(style = style)
Expand Down
6 changes: 3 additions & 3 deletions R/ChiSquare.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' @title `r ChiSquare$private_fields$.name`
#'
#' @description Performs chi-square statistic based permutation test on contingency tables.
#' @description Performs chi-square statistic based permutation test on contingency tables.
#'
#' @aliases table.chisq
#'
Expand All @@ -15,11 +15,11 @@ ChiSquare <- R6Class(
inherit = ContingencyTableTest,
cloneable = FALSE,
public = list(
#' @description Create a new `ChiSquare` object.
#' @description Create a new `ChiSquare` object.
#'
#' @template init_params
#'
#' @return A `ChiSquare` object.
#' @return A `ChiSquare` object.
initialize = function(
type = c("permu", "asymp"),
n_permu = 0L
Expand Down
2 changes: 1 addition & 1 deletion R/ContingencyTableTest.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' @title ContingencyTableTest Class
#'
#' @description This class specializes `PermuTest` for permutation tests for contingency tables. Note that it is not recommended to create objects of this class directly.
#' @description This class specializes `PermuTest` for permutation tests for contingency tables. Note that it is not recommended to create objects of this class directly.
#'
#'
#' @export
Expand Down
8 changes: 4 additions & 4 deletions R/Correlation.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' @title `r Correlation$private_fields$.name`
#'
#' @description Performs correlation coefficient based two sample permutation test on data vectors.
#' @description Performs correlation coefficient based two sample permutation test on data vectors.
#'
#' @aliases association.corr
#'
Expand All @@ -15,12 +15,12 @@ Correlation <- R6Class(
inherit = TwoSampleAssociationTest,
cloneable = FALSE,
public = list(
#' @description Create a new `Correlation` object.
#' @description Create a new `Correlation` object.
#'
#' @template init_params
#' @param method a character string indicating which correlation coefficient is to be computed.
#' @param method a character string indicating which correlation coefficient is to be computed.
#'
#' @return A `Correlation` object.
#' @return A `Correlation` object.
initialize = function(
type = c("permu", "asymp"), method = c("pearson", "kendall", "spearman"),
alternative = c("two_sided", "less", "greater"), n_permu = 0L
Expand Down
6 changes: 3 additions & 3 deletions R/Difference.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' @title `r Difference$private_fields$.name`
#'
#' @description Performs mean based two sample permutation test on data vectors.
#' @description Performs mean based two sample permutation test on data vectors.
#'
#' @aliases twosample.difference
#'
Expand All @@ -14,11 +14,11 @@ Difference <- R6Class(
inherit = TwoSampleTest,
cloneable = FALSE,
public = list(
#' @description Create a new `Difference` object.
#' @description Create a new `Difference` object.
#'
#' @template init_params
#'
#' @return A `Difference` object.
#' @return A `Difference` object.
initialize = function(
method = c("mean", "median"),
alternative = c("two_sided", "less", "greater"), n_permu = 0L
Expand Down
6 changes: 3 additions & 3 deletions R/Friedman.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' @title `r Friedman$private_fields$.name`
#'
#' @description Performs Friedman test on data for a randomized complete block design.
#' @description Performs Friedman test on data for a randomized complete block design.
#'
#' @aliases rcbd.friedman
#'
Expand All @@ -15,11 +15,11 @@ Friedman <- R6Class(
inherit = RCBD,
cloneable = FALSE,
public = list(
#' @description Create a new `Friedman` object.
#' @description Create a new `Friedman` object.
#'
#' @template init_params
#'
#' @return A `Friedman` object.
#' @return A `Friedman` object.
initialize = function(
type = c("permu", "asymp"),
n_permu = 0L
Expand Down
6 changes: 3 additions & 3 deletions R/JonckheereTerpstra.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' @title `r JonckheereTerpstra$private_fields$.name`
#'
#' @description Performs k sample Jonckheere-Terpstra Test on data vectors.
#' @description Performs k sample Jonckheere-Terpstra Test on data vectors.
#'
#' @aliases ksample.jt
#'
Expand All @@ -15,11 +15,11 @@ JonckheereTerpstra <- R6Class(
inherit = KSampleTest,
cloneable = FALSE,
public = list(
#' @description Create a new `JonckheereTerpstra` object.
#' @description Create a new `JonckheereTerpstra` object.
#'
#' @template init_params
#'
#' @return A `JonckheereTerpstra` object.
#' @return A `JonckheereTerpstra` object.
initialize = function(
type = c("permu", "asymp"),
alternative = c("two_sided", "less", "greater"), n_permu = 0L
Expand Down
2 changes: 1 addition & 1 deletion R/KSampleTest.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' @title KSampleTest Class
#'
#' @description This class specializes `PermuTest` for k sample permutation tests. Note that it is not recommended to create objects of this class directly.
#' @description This class specializes `PermuTest` for k sample permutation tests. Note that it is not recommended to create objects of this class directly.
#'
#'
#' @export
Expand Down
13 changes: 7 additions & 6 deletions R/KolmogorovSmirnov.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' @title `r KolmogorovSmirnov$private_fields$.name`
#'
#' @description Performs two sample Kolmogorov-Smirnov test on data vectors.
#' @description Performs two sample Kolmogorov-Smirnov test on data vectors.
#'
#' @aliases twosample.ks
#'
Expand All @@ -14,11 +14,11 @@ KolmogorovSmirnov <- R6Class(
inherit = TwoSampleTest,
cloneable = FALSE,
public = list(
#' @description Create a new `KolmogorovSmirnov` object.
#' @description Create a new `KolmogorovSmirnov` object.
#'
#' @template init_params
#'
#' @return A `KolmogorovSmirnov` object.
#' @return A `KolmogorovSmirnov` object.
initialize = function(n_permu = 0L) {
super$initialize(alternative = "greater", n_permu = n_permu)
}
Expand All @@ -30,10 +30,11 @@ KolmogorovSmirnov <- R6Class(
m <- length(private$.data$x)
n <- length(private$.data$y)

tmp <- rep.int(1 / m, m + n)
geq_m <- -1 / n
leq_m <- rep.int(1 / m, m + n)
private$.statistic_func <- function(x, y) {
max(abs(cumsum(`[<-`(tmp, order(c(x, y)) <= m, -1 / n))))
max(abs(cumsum(`[<-`(leq_m, order(c(x, y)) > m, geq_m))))
}
}
)
)
)
8 changes: 4 additions & 4 deletions R/KruskalWallis.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' @title `r KruskalWallis$private_fields$.name`
#'
#' @description Performs k sample Kruskal-Wallis Test on data vectors.
#' @description Performs k sample Kruskal-Wallis Test on data vectors.
#'
#' @aliases ksample.kw
#'
Expand All @@ -15,12 +15,12 @@ KruskalWallis <- R6Class(
inherit = KSampleTest,
cloneable = FALSE,
public = list(
#' @description Create a new `KruskalWallis` object.
#' @description Create a new `KruskalWallis` object.
#'
#' @template init_params
#' @param type a character string specifying the way to calculate p-values, must be one of `"permu"` (default) or `"asymp"`.
#' @param type a character string specifying the way to calculate p-values, must be one of `"permu"` (default) or `"asymp"`.
#'
#' @return A `KruskalWallis` object.
#' @return A `KruskalWallis` object.
initialize = function(
type = c("permu", "asymp"),
n_permu = 0L, scoring = c("rank", "vw", "expon")
Expand Down
25 changes: 9 additions & 16 deletions R/MultiCompT.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' @title `r MultiCompT$private_fields$.name`
#'
#' @description Performs t statistic based multiple comparison on data vectors.
#' @description Performs t statistic based multiple comparison on data vectors.
#'
#' @aliases multicomp.t
#'
Expand All @@ -15,28 +15,25 @@ MultiCompT <- R6Class(
inherit = MultipleComparison,
cloneable = FALSE,
public = list(
#' @description Create a new `MultiCompT` object.
#' @description Create a new `MultiCompT` object.
#'
#' @template init_params
#' @param conf_level a numeric value between zero and one giving the family-wise confidence level to use.
#' @param bonferroni a logical indicating whether to apply bonferroni adjustment.
#' @param conf_level a numeric value between zero and one giving the family-wise confidence level to use.
#'
#' @return A `MultiCompT` object.
initialize = function(
type = c("permu", "asymp"), bonferroni = TRUE,
type = c("permu", "asymp"), method = c("bonferroni", "no_bonferroni"),
conf_level = 0.95, n_permu = 0L, scoring = c("none", "rank", "vw", "expon")
) {
private$.type <- match.arg(type)
private$.bonferroni <- bonferroni
private$.method <- match.arg(method)

super$initialize(conf_level = conf_level, n_permu = n_permu, scoring = match.arg(scoring))
}
),
private = list(
.name = "Multiple Comparison Based on t Statistic",

.bonferroni = NULL,

.define = function() {
lengths <- vapply(
X = split(private$.data, names(private$.data)),
Expand Down Expand Up @@ -77,13 +74,9 @@ MultiCompT <- R6Class(
},

.calculate_extra = function() {
super$.calculate_extra()

if (private$.bonferroni) {
private$.multicomp$differ <- (
private$.p_value < (1 - private$.conf_level) / nrow(private$.multicomp)
)
}
private$.differ <- private$.p_value < (1 - private$.conf_level) / (
if (private$.method == "bonferroni") length(private$.p_value) else 1
)
}
)
)
Loading

0 comments on commit 103c393

Please sign in to comment.