## We can use the function to produce a closed testing tree
## A function to create power set
powerset <- function(x) {
sets <- lapply(1:(length(x)), function(i) combn(x, i, simplify = FALSE))
unlist(sets, recursive = FALSE)
}
n <- 3 # number of hypotheses
pn <- 2^n-1
pset <- powerset(seq(1, n, by = 1)) # create the power set
df <- data.frame(matrix(ncol = 1+n, nrow = 0)) # create the dataset
colnames(df) <- c("Test", paste0("H", seq(1, n, by = 1), sep = ""))
W0 <- c(1/3, 1/3, 1/3) # the weights of the graph
m <- rbind(H1 = c(0, 1/2, 1/2),
H2 = c(1/2, 0, 1/2),
H3 = c(1/2, 1/2, 0))
G0 <- matrix(m, nrow = 3, ncol = 3) # the transition matrix of the graph
for (j in 1:pn){
abc <- updategraph(S1 = pset[[j]], W0 = W0, G0 = G0)
temp <- rep("-", n)
temp[pset[[j]]] <- abc$W1
temp <- c(paste(pset[[j]], collapse = ""), temp)
df[j, ] <- temp
}
df # the dataframe lists the closed testing tree
Run the code above in your browser using DataLab