library(data.table)
#### Using simBuyseTest ####
## only point estimate
if (FALSE) {
powerBuyseTest(sim = simBuyseTest, sample.size = c(10, 25, 50, 75, 100),
formula = treatment ~ bin(toxicity), seed = 10, n.rep = 1000,
method.inference = "none", trace = 2, keep.pairScore = FALSE)
}
## point estimate with rejection rate
# \dontshow{
powerBuyseTest(sim = simBuyseTest, sample.size = c(10, 50, 100),
formula = treatment ~ bin(toxicity), seed = 10, n.rep = 10,
method.inference = "u-statistic", trace = 4)
# }
if (FALSE) {
powerBuyseTest(sim = simBuyseTest, sample.size = c(10, 50, 100),
formula = treatment ~ bin(toxicity), seed = 10, n.rep = 1000,
method.inference = "u-statistic", trace = 4)
}
#### Using user defined simulation function ####
## power calculation for Wilcoxon test
simFCT <- function(n.C, n.T){
out <- rbind(cbind(Y=stats::rt(n.C, df = 5), group=0),
cbind(Y=stats::rt(n.T, df = 5), group=1) + 1)
return(data.table::as.data.table(out))
}
simFCT2 <- function(n.C, n.T){
out <- rbind(cbind(Y=stats::rt(n.C, df = 5), group=0),
cbind(Y=stats::rt(n.T, df = 5), group=1) + 0.25)
return(data.table::as.data.table(out))
}
# \dontshow{
powerW <- powerBuyseTest(sim = simFCT, sample.size = c(5, 10,20,30,50,100),
n.rep = 10, formula = group ~ cont(Y))
summary(powerW)
# }
if (FALSE) {
powerW <- powerBuyseTest(sim = simFCT, sample.size = c(5,10,20,30,50,100),
n.rep = 1000, formula = group ~ cont(Y), cpus = "all")
summary(powerW)
}
## sample size needed to reach (approximately) a power
## based on summary statistics obtained on a large sample
if (FALSE) {
sampleW <- powerBuyseTest(sim = simFCT, power = 0.8, max.sample.size = 10000,
n.rep = 1000, formula = group ~ cont(Y), cpus = "all")
summary(sampleW) ## not very accurate but gives an order of magnitude
sampleW2 <- powerBuyseTest(sim = simFCT2,
power = 0.8, max.sample.size = 10000,
n.rep = 1000, formula = group ~ cont(Y), cpus = "all")
summary(sampleW2) ## more accurate with larger samples
}
Run the code above in your browser using DataLab