Skip to content

Commit

Permalink
update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
qddyy committed Dec 12, 2024
1 parent 8ac92ba commit bc83d91
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 22 deletions.
3 changes: 3 additions & 0 deletions R/PermuTest.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ PermuTest <- R6Class(
#' @param ... sample(s). Can be numeric vector(s) or a `data.frame` or `list` containing them.
#'
#' @return The object itself (invisibly).
#'
#' @details
#' A progress bar is shown by default. Use `options(LearnNonparam.pmt_progress = FALSE)` to disable it.
test = function(...) {
private$.raw_data <- get_data(match.call(), parent.frame())
private$.calculate()
Expand Down
25 changes: 14 additions & 11 deletions R/pmt.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,24 @@ pmts <- function(
#' @return a test object based on the specified statistic.
#'
#' @details
#' The test statistic can be defined using either `R` or `Rcpp`, with the `statistic` parameter specified as:
#' The test statistic can be defined using either R or Rcpp, with the `statistic` parameter specified as:
#'
#' - `R`: a function returning a closure that returns a double.
#' - `Rcpp`: a character string defining a captureless lambda (since C++11) returning another lambda that captures by value, accepts parameters of the same type as const references, and returns a double.
#' - R: a function returning a closure that returns a double.
#' - Rcpp: a character string defining a captureless lambda (since C++11) returning another lambda that captures by value, accepts parameters of the same type, and returns a double.
#'
#' When using `Rcpp`, the parameters for different `inherit` are listed as follows. Note that the parameter names are for illustration only.
#'
#' - `"twosample"`: `(Rcpp::NumericVector sample_1, Rcpp::NumericVector sample_2)`
#' - `"ksample"`: `(Rcpp::NumericVector combined_sample, Rcpp::IntegerVector one_based_group_index)`
#' - `"paired"`: `(Rcpp::NumericVector sample_1, Rcpp::NumericVector sample_2)`
#' - `"rcbd"`: `(Rcpp::NumericMatrix block_as_column_data)`
#' - `"association"`: `(Rcpp::NumericVector sample_1, Rcpp::NumericVector sample_2)`
#' - `"table"`: `(Rcpp::IntegerMatrix contingency_table)`
#' - `"twosample"`: `(const NumericVector& sample_1, const NumericVector& sample_2)`
#' - `"ksample"`: `(const NumericVector& combined_sample, const IntegerVector& one_based_group_index)`
#' - `"paired"`: `(const NumericVector& sample_1, const NumericVector& sample_2)`
#' - `"rcbd"`: `(const NumericMatrix& block_as_column_data)`
#' - `"association"`: `(const NumericVector& sample_1, const NumericVector& sample_2)`
#' - `"table"`: `(const IntegerMatrix& contingency_table)`
#'
#' Defining the test statistic using `R` follows a similar approach. The purpose of this design is to pre-calculate certain constants that remain invariant during permutation.
#' Defining the test statistic using R follows a similar approach. The purpose of this design is to pre-calculate certain constants that remain invariant during permutation.
#'
#' @note
#' The data is permuted in-place. Therefore, modifications to the data within `statistic` may lead to incorrect results. Since R has copy-on-modify semantics but C++ does not, it is recommended to pass const references when using `Rcpp`.
#'
#' @examples
#' x <- rnorm(5)
Expand Down Expand Up @@ -155,7 +158,7 @@ pmts <- function(
#' rcpp <- define_pmt(
#' inherit = "twosample",
#' n_permu = 1e5,
#' statistic = "[](NumericVector x, NumericVector y) {
#' statistic = "[](const NumericVector& x, const NumericVector& y) {
#' R_len_t m = x.size();
#' R_len_t n = y.size();
#' return [=](const NumericVector& x, const NumericVector& y) -> double {
Expand Down
4 changes: 4 additions & 0 deletions man/PermuTest.Rd

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

25 changes: 14 additions & 11 deletions man/pmt.Rd

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

0 comments on commit bc83d91

Please sign in to comment.