package randomizeBE for R on steroids [R for BE/BA]

posted by Helmut Homepage – Vienna, Austria, 2018-02-24 17:52  – Posting: # 18458
Views: 5,115

Hi Ana,

» By the function randomizeBE the result appears like this:
» Example: seed 2047732 blocksize: 2 created: 2018-02-24 12:38:06

Function RL4() of package randomizeBE generates a list containing as one of its elements the data frame rl. You can manipulate it as you like: Add a column for sex, shuffle it, and assign new subject numbers. If you want to see what is going on behind the scenes, uncomment the print-lines.

library(randomizeBE)
n         <- 16
blocksize <- n/2
random    <- RL4(nsubj=n, seqs=c("TR", "RT"),
                 blocksize=blocksize, randctrl=TRUE)
random$rl <- cbind(random$rl, sex="F", stringsAsFactors=FALSE) # "F" default
# change second half to "M"
random$rl$sex[which(random$rl$subject > blocksize)] <- "M"
# print(random$rl, row.names=FALSE) # intermediate
random$rl <- random$rl[sample(nrow(random$rl)), ] # shuffle
# print(random$rl, row.names=FALSE) # intermediate
random$rl$subject <- 1:n # new subject numbers
print(random) # final


Gave on my machine without a specified seed (i.e., based on the system clock and the process ID)

Randomization table          created: 2018-02-24 17:51:34
(seed: 7952217 blocksize: 8 )

 subject seqno sequence sex
       1     1       TR   F
       2     2       RT   M
       3     1       TR   F
       4     1       TR   M
       5     2       RT   F
       6     1       TR   F
       7     2       RT   M
       8     2       RT   M
       9     1       TR   M
      10     1       TR   M
      11     2       RT   M
      12     2       RT   F
      13     1       TR   F
      14     2       RT   F
      15     1       TR   M
      16     2       RT   F


You have to give the code in the SAP. Otherwise an assessor will not be able to reproduce it.

If you want to get output similar to your original post, add these lines before the final print(random)

random$rl <- cbind(random$rl, per.1=NA, per.2=NA)
random$rl$per.1 <- paste0(substring(random$rl$sequence, 1, 1), "   ")
random$rl$per.2 <- paste0(substring(random$rl$sequence, 2, 2), "   ")
random$rl$sequence <- NULL
random$rl <- random$rl[, c("subject", "sex", "seqno", "per.1", "per.2")]
names(random$rl) <- c("sujeito", "sexo", "seq", "period 1", "period 2")


to get:

Randomization table          created: 2018-02-24 17:51:34
(seed: 7952217 blocksize: 8 )

 sujeito sexo seq period 1 period 2
       1    F   1     T        R   
       2    M   2     R        T   
       3    F   1     T        R   
       4    M   1     T        R   
       5    F   2     R        T   
       6    F   1     T        R   
       7    M   2     R        T   
       8    M   2     R        T   
       9    M   1     T        R   
      10    M   1     T        R   
      11    M   2     R        T   
      12    F   2     R        T   
      13    F   1     T        R   
      14    F   2     R        T   
      15    M   1     T        R   
      16    F   2     R        T   




Edit: Don’t use this code. For an update see this post.

Cheers,
Helmut Schütz
[image]

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

Complete thread:

Activity
 Mix view
Bioequivalence and Bioavailability Forum |  Admin contact
19,437 posts in 4,125 threads, 1,325 registered users;
online 7 (1 registered, 6 guests [including 6 identified bots]).
Forum time (Europe/Vienna): 02:29 CEST

On two occasions I have been asked,—“Pray, Mr. Babbage,
if you put into the machine wrong figures,…
will the right answers come out?”

I am not able rightly to apprehend the kind of confusion of ideas
that could provoke such a question.    Charles Babbage

The BIOEQUIVALENCE / BIOAVAILABILITY FORUM is hosted by
BEBAC Ing. Helmut Schütz
HTML5