library(data.table)
library(BuyseTest)
#### simulate data ####
set.seed(11)
n <- 4
dt <- rbind(data.table(score = rnorm(n), group = "A"),
data.table(score = rnorm(2*n), group = "B"),
data.table(score = rnorm(3*n), group = "C"))
dt$index <- 1:NROW(dt)
#### estimation ####
score.casino <- dt$score
## naive casino (by hand)
M.score <- outer(dt[group=="A",score],score.casino,function(x,y){x>y+0.5*(x==y)})
mean(M.score)
## naive casino (via BuyseTest)
CasinoTest(group ~ cont(score), data = dt, type = "weighted")
## harmonic casino (by hand)
hweight <- unlist(tapply(dt$group, dt$group, function(x){rep(1/length(x),length(x))}))
M.scoreW <- sweep(M.score, MARGIN = 2, FUN = "*", STATS = NROW(dt)*hweight/3)
mean(M.scoreW)
## harmonic casino (via BuyseTest)
CasinoTest(group ~ cont(score), data = dt, type = "unweighted")
#### Relative liver weights data (Brunner 2018, table 4.1, page 183) ####
liverW <- rbind(
data.frame(value = c(3.78, 3.40, 3.29, 3.14, 3.55, 3.76, 3.23, 3.31),
group = "Placebo"),
data.frame(value = c(3.46,3.98,3.09,3.49,3.31,3.73,3.23),
group = "Dose 1"),
data.frame(value = c(3.71, 3.36, 3.38, 3.64, 3.41, 3.29, 3.61, 3.87),
group = "Dose 2"),
data.frame(value = c(3.86,3.80,4.14,3.62,3.95,4.12,4.54),
group = "Dose 3"),
data.frame(value = c(4.14,4.11,3.89,4.21,4.81,3.91,4.19, 5.05),
group = "Dose 4")
)
liverW$valueU <- liverW$value + (1:NROW(liverW))/1e6
## same as table 4.1, page 183 in Brunner et al (2018)
CasinoTest(group ~ cont(value), data = liverW, type = "weighted", add.halfNeutral = TRUE)
CasinoTest(group ~ cont(valueU), data = liverW, type = "unweighted", add.halfNeutral = TRUE)
Run the code above in your browser using DataLab