pmt("twosample.wilcoxon")
pmts()
# \donttest{
r <- define_pmt(
inherit = "twosample", rejection = "lr", n_permu = 1e5,
statistic = function(x, y) {
m <- length(x)
n <- length(y)
function(x, y) sum(x) / m - sum(y) / n
}
)
cpp <- define_pmt(
inherit = "twosample", rejection = "lr", n_permu = 1e5,
statistic = "[](NumericVector x, NumericVector y) {
R_len_t n_x = x.size();
R_len_t n_y = y.size();
return [n_x, n_y](const NumericVector x, const NumericVector y) {
double sum_x = 0;
double sum_y = 0;
for(auto x_i : x) sum_x += x_i;
for(auto y_i : y) sum_y += y_i;
return sum_x / n_x - sum_y / n_y;
};
}"
)
x <- rnorm(100)
y <- rnorm(100, 1)
options(LearnNonparam.pmt_progress = FALSE)
system.time(r$test(x, y))
system.time(cpp$test(x, y))
# }
Run the code above in your browser using DataLab