On Apr 27, 2010, at 4:40 AM, Wei Lun Norphos wrote:

> Hi,
> 
> 
> 
> I‚m new to R (just installed today) and I‚m trying to figure out how to do
> stratified randomisation using it. My google search expedition has lead me
> to believe that blockrand package will most probably be the answer to it.
> 
> 
> 
> I‚ve played around with blockrand for awhile and tried the sample code:
> 
> 
> 
> library(blockrand)
> 
> 
> 
> ##stratified by sex
> 
> male <- blockrand(n=100, id.prefix='M', block.prefix='M',stratum='Male')
> 
> female <- blockrand(n=100, id.prefix='F', block.prefix='F',stratum='Female')
> 
> 
> 
> my.study <- rbind(male,female)
> 
> my.mystudy
> 
> 
> 
> this generates a beautiful list of randomised list perfect stratified by
> sex. However, i cannot figure out how i can add in additional stratification
> besides sex. It would be great if someone can point me to the right
> direction J
> 
> 
> 
> Thanks!


As per the Details section of ?blockrand (which it appears that you have read):

"For stratified studies the blockrand function should run once each for each 
stratum using the stratum argument to specify the current stratum (and using 
id.prefix and block.prefix to keep the id's unique). The separate data frames 
can then be combined using rbind if desired."


So if you have 2 stratifying variables [Gender (Male/Female) and Diabetes 
(Yes/No)], run blockrand() once for each of the four possible combinations:


  Male.DiabYes <- blockrand(n = 100, id.prefix = 'M.DY', 
                            block.prefix = 'M.DY', stratum = 'Male-DiabYes')

  Male.DiabNo <- blockrand(n = 100, id.prefix = 'M.DN', 
                           block.prefix = 'M.DN', stratum = 'Male-DiabNo')

  Female.DiabYes <- blockrand(n = 100, id.prefix = 'F.DY', 
                              block.prefix = 'F.DY', stratum = 'Female-DiabYes')

  Female.DiabNo <- blockrand(n = 100, id.prefix = 'F.DN', 
                             block.prefix = 'F.DN', stratum = 'Female-DiabNo')



Since there is a practical limit on the number of strata when randomizing using 
this approach, this should not get overly complicated.

Lastly, blockrand() uses the sample() function internally to generate the 
blocks. Be sure to use ?set.seed to define the RNG seed to enable you to 
reproduce the block sequencing in the future and/or to be sure to differentiate 
testing blocks versus production blocks by using differing seeds for each run.

HTH,

Marc Schwartz

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to