Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(Rcpp)
- sourceCpp("dist_test.cpp")
- sigLvl <- 0.03
- # case 1
- X <- rnorm(40, 4, 10)
- Y <- rnorm(20, 4, 10)
- st <- proc.time()
- testStat <- dist_test(X, Y, c(0.1, 0.25, 0.5, 0.75, 0.9), 10000)
- proc.time() - st
- if (any(abs(testStat) > qnorm(1-sigLvl))) {
- message("Two datasets are different.")
- } else {
- message("Two datasets are the same.")
- }
- # case 2
- X <- rnorm(40, 4, 7)
- Y <- rnorm(20, 4, 7)
- st <- proc.time()
- testStat <- dist_test(X, Y, c(0.1, 0.25, 0.5, 0.75, 0.9), 10000)
- proc.time() - st
- if (any(abs(testStat) > qnorm(1-sigLvl))) {
- message("Two datasets are different.")
- } else {
- message("Two datasets are the same.")
- }
- ## general test
- mean(sapply(1:1e4, function(i){
- X <- rnorm(40, 4, 7)
- Y <- rnorm(20, 4, 10)
- any(abs(dist_test(X, Y, c(0.1, 0.25, 0.5, 0.75, 0.9), 10000)) > qnorm(1-0.01))
- }))
- # 0.1706
- mean(sapply(1:1e4, function(i){
- X <- rnorm(40, 4, 7)
- Y <- rnorm(20, 4, 14)
- any(abs(dist_test(X, Y, c(0.1, 0.25, 0.5, 0.75, 0.9), 10000)) > qnorm(1-0.01))
- }))
- # 0.4274
- mean(sapply(1:1e4, function(i){
- X <- rnorm(40, 4, 7)
- Y <- rnorm(20, 8, 7)
- any(abs(dist_test(X, Y, c(0.1, 0.25, 0.5, 0.75, 0.9), 10000)) > qnorm(1-0.01))
- }))
- # 0.5243
- mean(sapply(1:1e4, function(i){
- X <- rnorm(40, 4, 10)
- Y <- rnorm(20, 4, 10)
- any(abs(dist_test(X, Y, c(0.1, 0.25, 0.5, 0.75, 0.9), 10000)) > qnorm(1-0.01))
- }))
- # 0.1027
- ## general test 2
- mean(sapply(1:1e4, function(i){
- X <- rnorm(40, 4, 7)
- Y <- rnorm(20, 4, 10)
- sum(abs(dist_test(X, Y, c(0.1, 0.25, 0.5, 0.75, 0.9), 10000)) > qnorm(1-0.01)) >= 2
- }))
- # 0.041
- mean(sapply(1:1e4, function(i){
- X <- rnorm(40, 4, 7)
- Y <- rnorm(20, 4, 14)
- sum(abs(dist_test(X, Y, c(0.1, 0.25, 0.5, 0.75, 0.9), 10000)) > qnorm(1-0.01)) >= 2
- }))
- # 0.139
- mean(sapply(1:1e4, function(i){
- X <- rnorm(40, 4, 7)
- Y <- rnorm(20, 8, 7)
- sum(abs(dist_test(X, Y, c(0.1, 0.25, 0.5, 0.75, 0.9), 10000)) > qnorm(1-0.01)) >= 2
- }))
- # 0.291
- mean(sapply(1:1e4, function(i){
- X <- rnorm(40, 4, 10)
- Y <- rnorm(20, 4, 10)
- sum(abs(dist_test(X, Y, c(0.1, 0.25, 0.5, 0.75, 0.9), 10000)) > qnorm(1-0.01)) >= 2
- }))
- # 0.0193
- ## general test 3
- mean(sapply(1:1e4, function(i){
- X <- rnorm(40, 4, 7)
- Y <- rnorm(20, 4, 10)
- absStat <- abs(dist_test(X, Y, c(0.1, 0.25, 0.5, 0.75, 0.9), 10000))
- sum(absStat > qnorm(1-0.01)) >= 1 && sum(absStat > qnorm(1-0.03)) >= 2
- }))
- # 0.092
- mean(sapply(1:1e4, function(i){
- X <- rnorm(40, 4, 7)
- Y <- rnorm(20, 4, 14)
- absStat <- abs(dist_test(X, Y, c(0.1, 0.25, 0.5, 0.75, 0.9), 10000))
- sum(absStat > qnorm(1-0.01)) >= 1 && sum(absStat > qnorm(1-0.03)) >= 2
- }))
- # 0.2643
- mean(sapply(1:1e4, function(i){
- X <- rnorm(40, 4, 7)
- Y <- rnorm(20, 8, 7)
- absStat <- abs(dist_test(X, Y, c(0.1, 0.25, 0.5, 0.75, 0.9), 10000))
- sum(absStat > qnorm(1-0.01)) >= 1 && sum(absStat > qnorm(1-0.03)) >= 2
- }))
- # 0.432
- mean(sapply(1:1e4, function(i){
- X <- rnorm(40, 4, 10)
- Y <- rnorm(20, 4, 10)
- absStat <- abs(dist_test(X, Y, c(0.1, 0.25, 0.5, 0.75, 0.9), 10000))
- sum(absStat > qnorm(1-0.01)) >= 1 && sum(absStat > qnorm(1-0.03)) >= 2
- }))
- # 0.046
Add Comment
Please, Sign In to add comment