library(data.table)
#### Using simBuyseTest ####
## save time by not generating TTE outcomes
simBuyseTest2 <- function(...){simBuyseTest(..., argsCont = NULL, argsTTE = NULL)}
## only point estimate
if (FALSE) {
pBT <- powerBuyseTest(sim = simBuyseTest2, sample.size = c(10, 25, 50, 75, 100),
formula = treatment ~ bin(toxicity), seed = 10, n.rep = 1000,
method.inference = "none", keep.pairScore = FALSE, cpus = 5)
summary(pBT)
model.tables(pBT)
}
## point estimate with rejection rate
# \dontshow{
powerBuyseTest(sim = simBuyseTest2, 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 = simBuyseTest2, 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, formula = group ~ cont(Y),
n.rep = c(1000,10), max.sample.size = 2000, cpus = 5,
seed = 10)
nobs(sampleW)
summary(sampleW) ## not very accurate but gives an order of magnitude
sampleW2 <- powerBuyseTest(sim = simFCT2, power = 0.8, formula = group ~ cont(Y),
n.rep = c(1000,10), max.sample.size = 2000, cpus = 5,
seed = 10)
summary(sampleW2) ## more accurate when the sample size needed is not too small
}
Run the code above in your browser using DataLab