randomization [🇷 for BE/BA]

posted by ElMaestro  – Denmark, 2018-02-24 18:32 (1857 d 06:50 ago) – Posting: # 18457
Views: 12,910

Hello Ana Cristina,

I am thinking you can play around with this:


Ana.Cristinas.Randomizer2=function(Seed, N, WriteFile=F)
{
  if (N %% 4 != 0) {cat("N not divisible by four.!\n");return("Error.")}
  Gender=rep(c("F", "M"), N/2)
  Subject=c(1:N)
  Seqx=c(rep("TR", N/2), rep("RT", N/2))
  SeqF=sample(Seqx, replace=F)
  SeqM=sample(Seqx, replace=F)
  Seq=NULL
  for (i in 1:(N/2)) Seq=c(Seq, SeqF[i], SeqM[i])
  TrtP1=substr(Seq,1,1)
  TrtP2=substr(Seq,2,2)
  Rslt=data.frame(Subject, Gender, Seq, TrtP1, TrtP2)
  L1=paste("\n\nDate: ", format(Sys.Date(), format="%B %d %Y"),
     " Seed=", Seed, "\n\n", sep="")
  L2="\n\n\n\n\n______________________________\n"
  L3="Signature, date\n"
  if (WriteFile)
  {
    FN=paste(format(Sys.Date(), format="%B %d %Y"), " ", Seed,".txt", sep="")
    sink(file=FN)
    cat(L1)
    print(Rslt, row.names=F)
    cat(L2)
    cat(L3)   
    sink()
  }
  cat(L1)
  print(Rslt)
  return("Success.")
}

##can be run with e.g.
Ana.Cristinas.Randomizer2(12341234, 16, TRUE)


When the last argument is TRUE the function will print the randomisation code into a text file which is dated, contains the seed and which you can print and date+sign by hand. The filename is unique to the combination of date and seed.

Pass or fail!
ElMaestro

Complete thread:

UA Flag
Activity
 Admin contact
22,555 posts in 4,724 threads, 1,606 registered users;
16 visitors (0 registered, 16 guests [including 12 identified bots]).
Forum time: 02:23 CEST (Europe/Vienna)

Science is wonderfully equipped to answer the question “How?”
but it gets terribly confused when you ask the question “Why?”    Erwin Chargaff

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