(Pseudo-) random numbers, algos, seeds [R for BE/BA]

posted by Helmut Homepage – Vienna, Austria, 2019-08-26 12:28 (390 d 00:54 ago) – Posting: # 20523
Views: 2,919

Hi sury,

we had to edit 78% of your replies (deleting TOFU). This is the first warning.

» Even though when we specify the Block size, we are getting repeated seqno within the block in R.

By chance! You know what random means? Here another one:

library(randomizeBE)
print(RL4(nsubj = 12, blocksize = 6), sumry = TRUE)

Randomization table          created: 2019-08-26 12:26:28
(seed: 1742219 blocksize: 6 )

 subject seqno sequence
       1     1       TR
       2     1       TR
       3     2       RT
       4     1       TR
       5     2       RT
       6     2       RT
       7     1       TR
       8     2       RT
       9     1       TR
      10     1       TR
      11     2       RT
      12     2       RT

Summary of randomisation

12 subjects randomized into 2 sequence groups.
Number of subjects in sequence groups:
RT TR
 6  6
Runs test of randomness: p.value=0.5448


Block 1 (1– 6): 1, 1, 2, 1, 2, 2
Block 2 (7–12): 1, 2, 1, 1, 2, 2


» But when we do in SAS …

I thought that

» » » » » » But my SAS Licence got expired
»
» … we get different seqno (ex: 1,2) within the block.
»
» In SAS:
»
» Output:
»
» blocks sequence
» 4      1
» 4      2
» 5      2
» 5      1
» 6      2
» 6      1
» 1      1
» 1      2
» 2      2
» 2      1
» 3      2
» 3      1

»
» the seqno within the block is not getting repeated in SAS Output

Sorry, now you’ve lost me.
Block 1 (1–3): 1, 2, 2, 1, 2, 1
Block 2 (4–6): 1, 2, 2, 1, 2, 1


What do you want to achieve? Reproduce one randomization by another? Only possible if
Hoping to get the same randomization with different software is futile.

Example of simulating the empiric type I error (TIE) in PowerTOST (where you can also set a seed). If the argument setseed is missing, it is set to TRUE (in order to reproduce results). When you set it to FALSE, different seeds are used:

library(PowerTOST)
runs  <- 12
CV    <- 0.20
n     <- sampleN.TOST(CV = CV, details = FALSE, print = FALSE)[["Sample size"]]
res   <- data.frame(run = 1:runs, seed = c("missing", TRUE, rep(FALSE, runs - 2)),
                    TIE = 0, sig = "", stringsAsFactors = FALSE)
nsims <- 1e6
sig   <- binom.test(0.05*nsims, nsims, alternative = "less")$conf.int[2]
res$TIE[1] <- power.TOST.sim(CV = CV, theta0 = 1.25, nsims = nsims, n = n)
for (j in 2:runs) {
  res$TIE[j] <- power.TOST.sim(CV = CV, theta0 = 1.25, nsims = nsims, n = n,
                               setseed = as.logical(res$seed[j]))
}
res$sig[res$TIE > sig] <- "*"
print(res, row.names = FALSE)

 run    seed      TIE sig
   1 missing 0.050188   
   2    TRUE 0.050188   

   3   FALSE 0.049840   
   4   FALSE 0.049886   
   5   FALSE 0.050003   
   6   FALSE 0.050103   
   7   FALSE 0.049841   
   8   FALSE 0.049945   
   9   FALSE 0.050264   
  10   FALSE 0.050543   *
  11   FALSE 0.049727   
  12   FALSE 0.049942

We get the same numbers in first two runs but different ones in the others. Do you get the idea?
BTW, we know that the TIE of TOST is the nominal α or less. In simulations the empiric TIE might be higher. In run 10 the TIE was even significantly >0.05 (limit 0.05036) – more often (9.1%) than expected.
However, rolling the dice 1,000 times, I got 496 times ≤0.05 and 504 times >0.05 (5.00% significantly >0.05). Welcome to the world of chance and the wonders of Mersenne Twister. ;-)

Dif-tor heh smusma 🖖
Helmut Schütz
[image]

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

Complete thread:

Activity
 Admin contact
21,068 posts in 4,392 threads, 1,465 registered users;
online 18 (0 registered, 18 guests [including 11 identified bots]).
Forum time: Saturday 13:22 CEST (Europe/Vienna)

The purpose of models is not to fit the data,
but to sharpen the questions.    Samuel Karlin

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