From fb17af3ccddd2c5e75e9204d780a5d10fad51075 Mon Sep 17 00:00:00 2001 From: qddyy Date: Tue, 17 Dec 2024 22:19:48 +0800 Subject: [PATCH] minor improvements --- DESCRIPTION | 2 +- NEWS.md | 54 ++++++++++++++++++++------------ R/AnsariBradley.R | 2 +- R/Friedman.R | 2 +- R/KolmogorovSmirnov.R | 2 +- R/Page.R | 2 +- R/RCBDOneWay.R | 3 +- R/do_call.R | 2 +- R/pmt.R | 10 +++--- inst/include/pmt/permutation.hpp | 21 +++++++------ man/pmt.Rd | 10 +++--- 11 files changed, 62 insertions(+), 48 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ef646969..d31261b1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: LearnNonparam Title: 'R6'-Based Flexible Framework for Permutation Tests -Version: 1.2.5 +Version: 1.2.6 Authors@R: person(given = "Yan", family = "Du", role = c("aut", "cre"), email = "isduyan@outlook.com", comment = c(ORCID = "0009-0009-1169-921X")) Description: Implements non-parametric tests from Higgins (2004, ISBN:0534387756), including tests for one sample, two samples, k samples, paired comparisons, blocked designs, trends and association. Built with 'Rcpp' for efficiency and 'R6' for flexible, object-oriented design, the package provides a unified framework for performing or creating custom permutation tests. diff --git a/NEWS.md b/NEWS.md index 28c86500..76ada71a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,17 @@ +# LearnNonparam 1.2.6 + +- R side + - Added more documentation + - Switched to version 3 serialization format + - Fixed the issue with parameter passing to `ggplot2::stat_bin` in `plot()` + - Added detection for missing values and zero-length data in `test()` + +- C++ side + - Improved the efficiency of calling R from C++ + - Enhanced the permuting efficiency in `rcbd.*`, `association.*`, and `table.*` + - Replaced `R_len_t` with `R_xlen_t` to support long vectors + - Replaced `Rcpp.h` with `Rcpp/Lightest` to reduce compilation time + # LearnNonparam 1.2.5 - Added support for `scoring` as an active binding in `define_pmt` @@ -7,39 +21,39 @@ # LearnNonparam 1.2.4 - R side - - Added support for custom scoring systems in `define_pmt` - - Enabled compatibility with C++ standard versions beyond C++14 in `define_pmt` - - Improved the performance of `KruskalWallis`, `OneWay`, and `Studentized` - - Replaced certain `warning()` calls with `stop()` - - Refined some text + - Added support for custom scoring systems in `define_pmt` + - Enabled compatibility with C++ standard versions beyond C++14 in `define_pmt` + - Improved the performance of `KruskalWallis`, `OneWay`, and `Studentized` + - Replaced certain `warning()` calls with `stop()` + - Refined some text - C++ side - - Enhanced permuting efficiency in `twosample_pmt` + - Enhanced the permuting efficiency in `twosample.*` # LearnNonparam 1.2.3 -- Improved `twosample_pmt` +- Improved `twosample.*` - Added examples - Fixed `SiegelTukey` and `ContingencyTableTest` # LearnNonparam 1.2.2 - R side - - Changed the default value of `n_permu` to `1e4` - - Added support for test statistics defined using Rcpp in `define_pmt` - - Added support for `null_value` other than zero in two-sample location tests - - Added support for `scoring` in `TwoSampleAssociationTest` - - Added a confidence interval for p-value in `print()` - - Added the `LearnNonparam.pmt_progress` option - - Added `attr(t$n_permu, "n_used")` - - Replaced `multicomp.*` with `multcomp.*` - - Replaced `KSampleF` and `RCBDF` with `OneWay` and `RCBDOneWay` - - Stopped exporting abstract classes (`TwoSampleTest`, `KSampleTest`, etc.) - - Improved the efficiency of `ChiSquare`, `Difference`, `JonckheereTerpstra`, `KruskalWallis`, `RatioMeanDeviance` and `Studentized` - - Fixed many bugs + - Changed the default value of `n_permu` to `1e4` + - Added support for test statistics defined using Rcpp in `define_pmt` + - Added support for `null_value` other than zero in two-sample location tests + - Added support for `scoring` in `TwoSampleAssociationTest` + - Added a confidence interval for p-value in `print()` + - Added the `LearnNonparam.pmt_progress` option + - Added `attr(t$n_permu, "n_used")` + - Replaced `multicomp.*` with `multcomp.*` + - Replaced `KSampleF` and `RCBDF` with `OneWay` and `RCBDOneWay` + - Stopped exporting abstract classes (`TwoSampleTest`, `KSampleTest`, etc.) + - Improved the efficiency of `ChiSquare`, `Difference`, `JonckheereTerpstra`, `KruskalWallis`, `RatioMeanDeviance` and `Studentized` + - Fixed many bugs - C++ side - - Introduced a new progress bar, which is built at compile time to minimize runtime overhead + - Introduced a new progress bar, which is built at compile time to minimize runtime overhead # LearnNonparam 1.2.1 diff --git a/R/AnsariBradley.R b/R/AnsariBradley.R index f0091b47..c6d244ad 100644 --- a/R/AnsariBradley.R +++ b/R/AnsariBradley.R @@ -89,4 +89,4 @@ AnsariBradley <- R6Class( private$.p_value <- get_p_continous(z, "norm", private$.side) } ) -) +) \ No newline at end of file diff --git a/R/Friedman.R b/R/Friedman.R index 3d82dccf..d5828d68 100644 --- a/R/Friedman.R +++ b/R/Friedman.R @@ -65,4 +65,4 @@ Friedman <- R6Class( ) } ) -) +) \ No newline at end of file diff --git a/R/KolmogorovSmirnov.R b/R/KolmogorovSmirnov.R index 3773fea2..f69a4417 100644 --- a/R/KolmogorovSmirnov.R +++ b/R/KolmogorovSmirnov.R @@ -48,4 +48,4 @@ KolmogorovSmirnov <- R6Class( private$.side <- "r" } ) -) +) \ No newline at end of file diff --git a/R/Page.R b/R/Page.R index dcf77f9b..ccde4526 100644 --- a/R/Page.R +++ b/R/Page.R @@ -64,4 +64,4 @@ Page <- R6Class( private$.p_value <- get_p_continous(z, "norm", private$.side) } ) -) +) \ No newline at end of file diff --git a/R/RCBDOneWay.R b/R/RCBDOneWay.R index 882897ca..d2edc8ae 100644 --- a/R/RCBDOneWay.R +++ b/R/RCBDOneWay.R @@ -69,5 +69,4 @@ RCBDOneWay <- R6Class( ) } ) -) - +) \ No newline at end of file diff --git a/R/do_call.R b/R/do_call.R index b0fc51c2..8b671fcd 100644 --- a/R/do_call.R +++ b/R/do_call.R @@ -27,4 +27,4 @@ do_call <- function(func, default = list(), fixed = list(), ...) { # All arguments will be evaluated within the `args` environment. # https://stackoverflow.com/a/25371509/23137996 eval(as.call(c(func, lapply(`names<-`(...args, ...args), as.name))), args) -} +} \ No newline at end of file diff --git a/R/pmt.R b/R/pmt.R index 7e18e0ca..7cdda23d 100644 --- a/R/pmt.R +++ b/R/pmt.R @@ -164,8 +164,8 @@ pmts <- function( #' rcpp <- define_pmt( #' inherit = "twosample", n_permu = 1e5, #' statistic = "[](const auto& x, const auto& y) { -#' auto m = x.size(); -#' auto n = y.size(); +#' auto m = x.length(); +#' auto n = y.length(); #' return [=](const auto& x, const auto& y) { #' return sum(x) / m - sum(y) / n; #' }; @@ -176,9 +176,9 @@ pmts <- function( #' # rcpp <- define_pmt( #' # inherit = "twosample", n_permu = 1e5, #' # statistic = "[](const NumericVector& x, const NumericVector& y) { -#' # R_xlen_t m = x.size(); -#' # R_xlen_t n = y.size(); -#' # return [=](const NumericVector& x, const NumericVector& y) -> double { +#' # R_xlen_t m = x.length(); +#' # R_xlen_t n = y.length(); +#' # return [m, n](const NumericVector& x, const NumericVector& y) -> double { #' # return sum(x) / m - sum(y) / n; #' # }; #' # }" diff --git a/inst/include/pmt/permutation.hpp b/inst/include/pmt/permutation.hpp index ba2df099..38829982 100644 --- a/inst/include/pmt/permutation.hpp +++ b/inst/include/pmt/permutation.hpp @@ -3,6 +3,9 @@ #include #include +template +using diff_t = typename std::iterator_traits::difference_type; + template T rand_int(T n) { @@ -12,12 +15,10 @@ T rand_int(T n) template void random_shuffle(T first, T last) { - using diff_t = typename std::iterator_traits::difference_type; - - diff_t n = std::distance(first, last); + diff_t n = std::distance(first, last); - for (diff_t i = 0; i < n - 1; i++) { - diff_t j = i + rand_int(n - i); + for (diff_t i = 0; i < n - 1; i++) { + diff_t j = i + rand_int(n - i); std::iter_swap(first + i, first + j); } } @@ -33,10 +34,10 @@ double n_permutation(T first, T last) { double A = 1.0; - typename std::iterator_traits::difference_type rep = 0; + diff_t rep = 0; auto val = *first; - for (auto it = first; it != last; it++) { + for (T it = first; it != last; it++) { A *= std::distance(first, it) + 1; if (*it == val) { A /= ++rep; @@ -50,19 +51,19 @@ double n_permutation(T first, T last) } template -auto random_shuffle(T& v) +auto random_shuffle(T&& v) { return random_shuffle(v.begin(), v.end()); } template -auto next_permutation(T& v) +auto next_permutation(T&& v) { return next_permutation(v.begin(), v.end()); } template -auto n_permutation(const T& v) +auto n_permutation(T&& v) { return n_permutation(v.begin(), v.end()); } \ No newline at end of file diff --git a/man/pmt.Rd b/man/pmt.Rd index 6da93ce8..538badfb 100644 --- a/man/pmt.Rd +++ b/man/pmt.Rd @@ -123,8 +123,8 @@ r <- define_pmt( rcpp <- define_pmt( inherit = "twosample", n_permu = 1e5, statistic = "[](const auto& x, const auto& y) { - auto m = x.size(); - auto n = y.size(); + auto m = x.length(); + auto n = y.length(); return [=](const auto& x, const auto& y) { return sum(x) / m - sum(y) / n; }; @@ -135,9 +135,9 @@ rcpp <- define_pmt( # rcpp <- define_pmt( # inherit = "twosample", n_permu = 1e5, # statistic = "[](const NumericVector& x, const NumericVector& y) { -# R_xlen_t m = x.size(); -# R_xlen_t n = y.size(); -# return [=](const NumericVector& x, const NumericVector& y) -> double { +# R_xlen_t m = x.length(); +# R_xlen_t n = y.length(); +# return [m, n](const NumericVector& x, const NumericVector& y) -> double { # return sum(x) / m - sum(y) / n; # }; # }"