Harsh

Author

Ilya Musabirov

Code
library(rstanarm)
library(dplyr)
library(stringr)
library(glue)
Show the code
sprintf_transformer <- function(text, envir) {
  m <- regexpr(":.+$", text)
  if (m != -1) {
    format <- substring(regmatches(text, m), 2)
    regmatches(text, m) <- ""
    res <- eval(parse(text = text, keep.source = FALSE), envir)
    do.call(sprintf, list(glue("%{format}"), res))
  } else {
    eval(parse(text = text, keep.source = FALSE), envir)
  }
}
Code
    N = 250
    nsim = 1000
    # f_transp <- sample(c(T,F), N, replace=TRUE)
    # f_example <- sample(c(T,F), N, replace=TRUE)
    # 
  pvals.t <- numeric(length = nsim)
  pvals.w <- numeric(length = nsim)
  for (i in 1:nsim) {
    y1 = rnorm(N, 3.6, 1.5) %>% round()
    y2 = rnorm(N, 4, 1.5) %>% round()
    pvals.w[i] <- wilcox.test(y1, y2)$p.value
    pvals.t[i] <- t.test(y1, y2)$p.value
}

(power = sum(pvals.t < 0.05)/nsim)
[1] 0.836
Code
(power = sum(pvals.w < 0.05)/nsim)
[1] 0.825