‘Two-at-a-Time’ approach with >3 treat­ments [Design Issues]

posted by Helmut Homepage – Vienna, Austria, 2022-06-12 22:10 (674 d 19:04 ago) – Posting: # 23054
Views: 2,124

Hi Shuanghe,

long time, no hear!

❝ I vaguelly recall that for 4x4 William design, each row (sequence) and each column (period) should contain A, B, C, and D each exactly once.

Absolutely correct.

❝ I think that there's a typo in the 3rd sequence of your first William design.

F**k & THX! You are right.

❝ Your 3rd and 4th column do not seem right. So 3rd period would have 2 Bs and 4th had 2 Ds. CABD should be CADB. So It would be ABCD/BDAC/CADB/DCBA.


An updated [image]-script which works for any number of treatments (tested for ≤ 8) at the end. Of course, more than five treatments in a higher-order crossover are not realistic due to the number of periods and likely a Balanced In­com­plete Block Design will be used instead. Not implemented yet.

An example for the maximum of treatments I ever came across:

 subject seqno sequence  IBD.1  IBD.2  IBD.3  IBD.4  IBD.5
       1     4   DAFCEB •AF••• ••F••B ••FC•• D•F••• ••F•E•
       2     6   FDEABC F••A•• F•••B• F••••C FD•••• F•E•••
       3     6   FDEABC F••A•• F•••B• F••••C FD•••• F•E•••
       4     3   CBAEDF ••A••F •B•••F C••••F ••••DF •••E•F
       5     2   BECFAD •••FA• B••F•• ••CF•• •••F•D •E•F••
       6     5   EFBDCA •F•••A •FB••• •F••C• •F•D•• EF••••
       7     1   ACDBFE A•••F• •••BF• •C••F• ••D•F• ••••FE
       8     1   ACDBFE A•••F• •••BF• •C••F• ••D•F• ••••FE
       9     2   BECFAD •••FA• B••F•• ••CF•• •••F•D •E•F••
      10     5   EFBDCA •F•••A •FB••• •F••C• •F•D•• EF••••
      11     3   CBAEDF ••A••F •B•••F C••••F ••••DF •••E•F
      12     4   DAFCEB •AF••• ••F••B ••FC•• D•F••• ••F•E•
      13     2   BECFAD •••FA• B••F•• ••CF•• •••F•D •E•F••
      14     6   FDEABC F••A•• F•••B• F••••C FD•••• F•E•••
      15     4   DAFCEB •AF••• ••F••B ••FC•• D•F••• ••F•E•
      16     1   ACDBFE A•••F• •••BF• •C••F• ••D•F• ••••FE
      17     5   EFBDCA •F•••A •FB••• •F••C• •F•D•• EF••••
      18     4   DAFCEB •AF••• ••F••B ••FC•• D•F••• ••F•E•
      19     1   ACDBFE A•••F• •••BF• •C••F• ••D•F• ••••FE
      20     3   CBAEDF ••A••F •B•••F C••••F ••••DF •••E•F
All extracted IBDs are balanced.

Sometimes sequences are imbalanced. In this example we have four subjects in sequences DAFCEB and FDEABC
and three subjects in each of the other four sequences. However, that’s not relevant because we aim at balance of the IBDs. If you want balance, specify bal <- TRUE. In the example it would require 24 subjects instead of 20.

Although there is just one Williams’ design for three treatments, there are six possible for four treatments, twelve for five, 120 for six, and 360 for seven. The function williams() of randomizeBE will arbitrarily select one of them.
If you run the script, the chance to get the same sequences like in my example is 1/120.

Edit: Don’t use this script. Use the one at the end of this post instead.

ntmt   <- 6     # number of treatments (at least 3)
CV     <- 0.20  # assumed CV
theta0 <- 0.95  # assumed T/R-ratio
target <- 0.80  # target (desired) power
bal    <- FALSE # TRUE if the study should have balanced sequences
make.equal <- function(n, nseq) {
  return(as.integer(nseq * (n %/% nseq + as.logical(n %% nseq))))
# sample size for evaluation by the ‘Two at a Time’ approach
# note that the design is specified as "2x2"

n      <- sampleN.TOST(CV = CV, theta0 = theta0, targetpower = target,
                       design = "2x2", print = FALSE)[["Sample size"]]
# sequences of a Williams’ design
seqs   <- williams(ntmt)
# alternatively specify your own vector:
# treatments must have only one character and the
# reference must have the highest lexical order
# a Latin Square with four treatments will work
#   seqs <- c("ABCR", "BCRA", "CRAB", "RABC")
# but this one will not
#   seqs <- c("T1T2T3R", "T2T3RT1", "T3RT1T2", "RT1T2T3")
# eventual uprounding if balance is requested

if (bal) n <- make.equal(n, length(seqs))
s      <- paste0(seqs, collapse = "")
# the last treatment in lexical order will act as the reference
s      <- paste(sort(unlist(strsplit(s, ""))), collapse = "")
ref    <- substr(s, nchar(s), nchar(s))
# extract treatment codes
trts   <- unique(c(strsplit(split = "", seqs), recursive = TRUE))
# extract tests in increasing order
tests  <- sort(trts[!trts == ref])
# get the randomization list
rand   <- suppressWarnings( # not relevant for TaT
            RL4(nsubj = n, seqs = seqs)$rl)
# generate columns for the IBDs
for (j in seq_along(tests)) {
  rand[[paste0("IBD.", j)]] <- NA
# build the IBDs
for (j in 1:nrow(rand)) {
  for (k in seq_along(tests)) {
    excl           <- tests[!tests == tests[k]]
    excl           <- paste0("[", paste(excl, collapse = ", "), "]")
    rand[j, 3 + k] <- gsub(excl, "•", rand$sequence[j])
# check IBDs for balance
checks <- rep(NA, length(tests))
for (j in seq_along(tests)) {
  checks[j] <- sum(lengths(regmatches(rand[3 + j],
                                               rand[3 + j])))) ==
               sum(lengths(regmatches(rand[3 + j],
                                               rand[3 + j]))))
txt    <-    paste("Sequences:", paste(seqs, collapse = ", "))
if (length(unique(checks)) == 1) { # all are TRUE
  txt <- paste(txt, "\nAll extracted IBDs are balanced.\n")
} else {                           # at least one of the IBDs is imbalanced
  txt <- paste(txt, "\nExtracted IBDs are imbalanced;",
               "check the sequences.\n")
print(rand, row.names = FALSE); cat(txt)

Dif-tor heh smusma 🖖🏼 Довге життя Україна! [image]
Helmut Schütz

The quality of responses received is directly proportional to the quality of the question asked. 🚮
Science Quotes

Complete thread:

UA Flag
 Admin contact
22,985 posts in 4,823 threads, 1,653 registered users;
41 visitors (0 registered, 41 guests [including 2 identified bots]).
Forum time: 17:15 CEST (Europe/Vienna)

Complex, statistically improbable things are by their nature
more difficult to explain than
simple, statistically probable things.    Richard Dawkins

The Bioequivalence and Bioavailability Forum is hosted by
BEBAC Ing. Helmut Schütz