pmt("twosample.wilcoxon")
pmts("ksample")
x <- rnorm(5)
y <- rnorm(5, 1)
t <- define_pmt(
inherit = "twosample",
scoring = base::rank, # equivalent to "rank"
statistic = function(...) function(x, y) sum(x)
)$test(x, y)$print()
t$scoring <- function(x) qnorm(rank(x) / (length(x) + 1)) # equivalent to "vw"
t$print()
t$n_permu <- 0
t$print()
# \donttest{
r <- define_pmt(
inherit = "twosample", n_permu = 1e5,
statistic = function(x, y) {
m <- length(x)
n <- length(y)
function(x, y) sum(x) / m - sum(y) / n
}
)
rcpp <- define_pmt(
inherit = "twosample", n_permu = 1e5,
statistic = "[](const auto& x, const auto& y) {
auto m = x.length();
auto n = y.length();
return [=](const auto& x, const auto& y) {
return sum(x) / m - sum(y) / n;
};
}"
)
# equivalent
# rcpp <- define_pmt(
# inherit = "twosample", n_permu = 1e5,
# statistic = "[](const NumericVector& x, const NumericVector& y) {
# 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;
# };
# }"
# )
options(LearnNonparam.pmt_progress = FALSE)
system.time(r$test(x, y))
system.time(rcpp$test(x, y))
# }
Run the code above in your browser using DataLab