sury
★    

India,
2019-08-23 15:39
(1679 d 04:06 ago)

Posting: # 20509
Views: 6,271
 

 Randomization Schedule in R [🇷 for BE/BA]

Hii all,

i am beginner to R programming

I just want to know about the randomization schedule generation using R Software. I am Core SAS Programmer. so we usually use the SAS PROC PLAN procedure for generating the randomization.

But my SAS Licence got expired and i want to opt the R Software. Please do help in this regards.

Also want to know whether the regulatory accepts the randomization schedule generated by R as the most of the CRO's use SAS software for the same.

Thanks in Advance


Edit: Category changed; see also this post #1[Helmut]
Helmut
★★★
avatar
Homepage
Vienna, Austria,
2019-08-24 18:31
(1678 d 01:13 ago)

@ sury
Posting: # 20513
Views: 5,508
 

 package randomizeBE

Hi sury,

❝ i want to opt the R Software. Please do help in this regards.


What about Google?

# Check whether the package is already installed,
# if not, get it form CRAN
package <- "randomizeBE"
inst    <- package %in% installed.packages()
if (length(package[!inst]) > 0) install.packages(package[!inst])
library(randomizeBE)        # attach it
help(package = randomizeBE) # the man-page
20 subjects, 2x2 crossover
RL4(n = 20, seqs = c("TR", "RT"))

Randomization table          created: 2019-08-24 16:18:21
(seed: 1266635 blocksize: 4 )

 subject seqno sequence
       1     1       TR
       2     2       RT
       3     1       TR
       4     2       RT
       5     1       TR
       6     2       RT
       7     1       TR
       8     2       RT
       9     2       RT
      10     1       TR
      11     1       TR
      12     2       RT
      13     2       RT
      14     2       RT
      15     1       TR
      16     1       TR
      17     1       TR
      18     1       TR
      19     2       RT
      20     2       RT


# another one (make the same call again)

Randomization table          created: 2019-08-24 16:18:55
(seed: 7330240 blocksize: 4 )

 subject seqno sequence
       1     1       TR
       2     1       TR
       3     2       RT
       4     2       RT
       5     2       RT
       6     2       RT
       7     1       TR
       8     1       TR
       9     2       RT
      10     1       TR
      11     1       TR
      12     2       RT
      13     2       RT
      14     2       RT
      15     1       TR
      16     1       TR
      17     1       TR
      18     2       RT
      19     1       TR
      20     2       RT


# reproduce the first one to make inspectors happy
RL4(n = 20, seqs = c("TR", "RT"), seed = 1266635)

Randomization table          created: 2019-08-24 16:19:49
(seed: 1266635 blocksize: 4 )

 subject seqno sequence
       1     1       TR
       2     2       RT
       3     1       TR
       4     2       RT
       5     1       TR
       6     2       RT
       7     1       TR
       8     2       RT
       9     2       RT
      10     1       TR
      11     1       TR
      12     2       RT
      13     2       RT
      14     2       RT
      15     1       TR
      16     1       TR
      17     1       TR
      18     1       TR
      19     2       RT
      20     2       RT


# 6-sequence Williams' design (one test and two references)
seqs <- sequences(design = "3x6x3", tmts = c("T", "R1", "R2"))
RL4(n = 18, seqs = seqs)

Randomization table          created: 2019-08-24 16:20:10
(seed: 7330240 blocksize: 12 6 )

 subject seqno sequence
       1     6    R2R1T
       2     2    R1R2T
       3     1    TR1R2
       4     5    R1TR2
       5     4    TR2R1
       6     6    R2R1T
       7     2    R1R2T
       8     3    R2TR1
       9     5    R1TR2
      10     1    TR1R2
      11     4    TR2R1
      12     3    R2TR1
      13     4    TR2R1
      14     2    R1R2T
      15     6    R2R1T
      16     5    R1TR2
      17     1    TR1R2
      18     3    R2TR1


# 2 group parallel
seqs <- suppressWarnings(sequences(design = "parallel"))
RL4(n = 20, seqs = seqs)

Randomization table          created: 2019-08-24 16:20:28
(seed: 613450 blocksize: 4 )

 subject seqno sequence
       1     2        B
       2     1        A
       3     1        A
       4     2        B
       5     2        B
       6     2        B
       7     1        A
       8     1        A
       9     1        A
      10     2        B
      11     2        B
      12     1        A
      13     2        B
      14     1        A
      15     1        A
      16     2        B
      17     1        A
      18     2        B
      19     2        B
      20     1        A


There is a glitch if design = "parallel". Hence, I suppressed the warnings. Currently it is not possible to define treatments codes with e.g., tmts = c("T", "R"). See Yung-jin’s post. Sooner or later Detlew will fix it.* ;-)

❝ Also want to know whether the regulatory accepts the randomization schedule generated by R as the most of the CRO's use SAS software for the same.


Regulators demand that the software is validated.1,2,3 Applicable to R, SAS as to any other (out of curiosity: How did you validate SAS’ PROC PLAN?). A goody4 and a quote from the FDA5

FDA does not require use of any specific software for statistical analyses, and statistical software is not explicitly discussed in Title 21 of the Code of Federal Regulations [e.g., in 21CFR part 11]. However, the software package(s) used for statistical analyses should be fully documented in the submission, including version and build identification.




  1. European Medicines Agency. GCP Inspectors Working Group. Reflection paper on expectations for electronic source data and data transcribed to electronic data collection tools in clinical trials. London, 9 June 2010. https://www.ema.europa.eu/en/documents/regulatory-procedural-guideline/reflection-paper-expectations-electronic-source-data-data-transcribed-electronic-data-collection_en.pdf
  2. International Council for Harmonisation. Integrated Addendum to ICH E6(R1): Guideline For Good Clinical Practice E6(R2). 9 November 2016. https://www.ich.org/fileadmin/Public_Web_Site/ICH_Products/Guidelines/Efficacy/E6/E6_R2__Step_4_2016_1109.pdf
  3. World Health Organization. Technical Report Series No. 996, Annex 9. Guidance for organizations performing in vivo bioequivalence studies (revision). Geneva, May 2016. https://www.who.int/medicines/publications/pharmprep/WHO_TRS_996_annex09.pdf
  4. The R Foundation for Statistical Computing. R: Regulatory Compliance and Validation Issues. A Guidance Document for the Use of R in Regulated Clinical Trial Environments. Vienna, March 25, 2018. [image] free resource.
  5. US FDA. Statistical Software Clarifying Statement. May 6, 2015. Study Data Standards.

  • See this post. Will take a couple of days until pre-compiled binaries will be available.

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

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

India,
2019-08-26 11:34
(1676 d 08:10 ago)

@ Helmut
Posting: # 20520
Views: 5,433
 

 package randomizeBE

Hii Helmut,

This helped me a lot....

but i have few more confusions in it, when we generate the randomization schedule in SAS using PROC PLAN Procedure, we generally take for example if subjects are 12, blocks will be 6 and if we generate the randomization we get the results as follows

Code:
proc plan ;
factors blocks=6 random sequence=2 random/ noprint;
output out=first sequence nvals= (1 2) random;
quit;
run;

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



when using BEAR Package in R we getting the following output

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

      11     2       TR
      12     2       TR



Comparison: when we run in SAS, within the block same sequence is not repeating, but when we run in R, we are getting the sequence repeated within the blocks. even though we are getting the P-value of 1.000 in R

but is it fine to get that.

Thanks in advance


Edit: Tabulators changed to spaces and BBcoded; see also this post #6[Helmut]
Helmut
★★★
avatar
Homepage
Vienna, Austria,
2019-08-26 12:35
(1676 d 07:10 ago)

@ sury
Posting: # 20521
Views: 5,409
 

 package randomizeBE

Hi sury,

❝ […] when we generate the randomization schedule in SAS using PROC PLAN Procedure, we generally take for example if subjects are 12, blocks will be 6…


As specified in your code.

factors blocks=6 random sequence=2 random/ noprint;


❝ Comparison: when we run in SAS, within the block same sequence is not repeating, but when we run in R, we are getting the sequence repeated within the blocks. even though we are getting the P-value of 1.000 in R


RTFM

If blocksize is missing it defaults to 2*number of sequences.


I guess you didn’t specify that you want a blocksize of 6. Hence, with two sequences you will get a blocksize of four:

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

Randomization table          created: 2019-08-26 10:28:28
(seed: 6284375
blocksize: 4 )

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


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.2259


print(RL4(nsubj = 12, blocksize = 6, seed = 6284375), sumry = TRUE)

Randomization table          created: 2019-08-26 10:28:29
(seed: 6284375
blocksize: 6 )

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


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.0693



❝ but is it fine to get that.


So what’s the problem?

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

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

India,
2019-08-26 13:54
(1676 d 05:50 ago)

@ Helmut
Posting: # 20522
Views: 5,389
 

 package randomizeBE

print(RL4(nsubj = 12, blocksize = 6, seed = 6284375), sumry = TRUE)


Randomization table          created: 2019-08-26 10:28:29

❝ (seed: 6284375 blocksize: 6 )


❝  subject seqno sequence
❝        1     2       RT
❝        2     2       RT
❝        3     2       RT
❝        4     1       TR
❝        5     1       TR
❝        6     1       TR

       7     2       RT

❝        8     2       RT
❝        9     2       RT
❝       10     1       TR

      11     1       TR

❝       12     1       TR


Even though when we specify the Block size, we are getting repeated seqno within the block in R. But when we do in SAS 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


Edit: Full quote removed. Please delete everything from the text of the original poster which is not necessary in understanding your answer; see also this post #5[Helmut]
Helmut
★★★
avatar
Homepage
Vienna, Austria,
2019-08-26 14:28
(1676 d 05:17 ago)

@ sury
Posting: # 20523
Views: 5,448
 

 (Pseudo-) random numbers, algos, seeds

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
  • same software (i.e., same AlGore rhythm) and
  • same seed of the (pseudo-) random number generator
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 🖖🏼 Довге життя Україна! [image]
Helmut Schütz
[image]

The quality of responses received is directly proportional to the quality of the question asked. 🚮
Science Quotes
yjlee168
★★★
avatar
Homepage
Kaohsiung, Taiwan,
2019-08-28 09:25
(1674 d 10:20 ago)

@ Helmut
Posting: # 20525
Views: 5,313
 

 how about randomly selected block sizes?

Dear Helmut & Detlew,

The block size in package randomizeBE is fixed and its deafult is set to 2*number of sequences. Is it better to set the blocksize as randomly selected as suggested in this article?

❝ ...RTFM

If blocksize is missing it defaults to 2*number of sequences.


All the best,
-- Yung-jin Lee
bear v2.9.1:- created by Hsin-ya Lee & Yung-jin Lee
Kaohsiung, Taiwan https://www.pkpd168.com/bear
Download link (updated) -> here
ElMaestro
★★★

Denmark,
2019-08-28 11:26
(1674 d 08:19 ago)

@ yjlee168
Posting: # 20526
Views: 5,309
 

 how about randomly selected block sizes?

Hi yjlee168,

❝ The block size in package randomizeBE is fixed and its deafult is set to 2*number of sequences. Is it better to set the blocksize as randomly selected as suggested in this article?


❝ ❝ ...RTFM

If blocksize is missing it defaults to 2*number of sequences.



I did not know of that paper or this kind of thinking - thank you for enlightening me.
I think the paper addresses bias through predictability. Imagine we have TR/RT and block size 4, and that you can tell the treatments apart though the study is supposed to be blind.
If you dose subject 1 and 2 in a given period with T then you can tell with certainty that the other two in the block will be given R.
BE trials tend to be open label. By this thinking the block size phenomenon would not affect the outcome or have the potential to bias it.

Noone says blocks are necessary at all. For trials at single centers in single groups, which acccount for the majority of BE trials, I don't see any particular need for blocks.

Pass or fail!
ElMaestro
UA Flag
Activity
 Admin contact
22,957 posts in 4,819 threads, 1,636 registered users;
67 visitors (0 registered, 67 guests [including 3 identified bots]).
Forum time: 18:45 CET (Europe/Vienna)

Nothing shows a lack of mathematical education more
than an overly precise calculation.    Carl Friedrich Gauß

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