Skip to contents

Getting started

Here’s how to easily nice_randomize for either within-subject or between-group!

Sure, you might just want to generate a random number n times, and hope each group gets approximately the same number of participants assigned to it. Or, you can make sure of this by making “blocks” without replacements. So if you had four groups, each block of four would contain each group once, in a random order, which you would then repeat. Let’s see this.

Load the rempsyc package:

Note: If you haven’t installed this package yet, you will need to install it via the following command: devtools::install_github("rempsyc/rempsyc"). Package devtools is necessary for this command. If you haven’t installed devtools yet, install it via install.packages("devtools").

Between-Group Design

Basic output with default options (3 conditions, 9 participants, between-group design):

##   id Condition
## 1  1         a
## 2  2         c
## 3  3         b
## 4  4         c
## 5  5         a
## 6  6         b
## 7  7         c
## 8  8         a
## 9  9         b

Specify design, number of conditions, number of participants, and names of conditions:

nice_randomize(design = "between", 
               Ncondition = 4, 
               n = 8, 
               condition.names = c("BP","CX","PZ","ZL"))
##   id Condition
## 1  1        PZ
## 2  2        BP
## 3  3        ZL
## 4  4        CX
## 5  5        BP
## 6  6        ZL
## 7  7        PZ
## 8  8        CX
# Warning: sample size needs to be a multiple of your number of groups if using "between"!
# FYI: condition names stand for popular antidepressants:
# BP = Bupropion, CX = Celexa, PZ = Prozac, ZL = Zoloft.

Be aware that this function won’t work for between-group designs unless your sample size is a multiple of your number of groups (so for 4 groups, sample size can’t be 5, 6, or 7, but you can have 4, 8, 12, etc., participants). You can still try otherwise but you will get an error and a warning message. That is because it works by “blocks” so some operations won’t be able to be completed otherwise.

Within-Group Design

Basic output with default options (3 conditions and 9 participants) but with within-subject design specified

nice_randomize(design = "within")
##   id Condition
## 1  1 a - c - b
## 2  2 a - b - c
## 3  3 c - a - b
## 4  4 c - a - b
## 5  5 c - b - a
## 6  6 c - a - b
## 7  7 a - c - b
## 8  8 a - c - b
## 9  9 a - b - c

Specify design, number of conditions, number of participants, and names of conditions:

Note that you could call your conditions anything (like a, b, c, etc.).

nice_randomize(design = "within", 
               Ncondition = 4, 
               n = 6, 
               condition.names = c("SV","AV","ST","AT"))
##   id         Condition
## 1  1 AV - AT - ST - SV
## 2  2 ST - AT - AV - SV
## 3  3 AV - AT - ST - SV
## 4  4 AV - ST - AT - SV
## 5  5 AT - ST - SV - AV
## 6  6 AV - AT - SV - ST
# FYI: condition names stand for forms of multisensory stimulation:
# SV = Synchronous Visual, AV = Asynchronous Visual, 
# ST = Synchronous Tactile, AT = Asynchronous Tactile.

Make a quick runsheet

A nice way to make a run sheet quickly (regardless of design) is by adding column names in advance with the col.names argument:

nice_randomized_subjects <- nice_randomize(design = "within", 
                                           Ncondition = 4, 
                                           n = 128,
                                           condition.names = c("SV","AV","ST","AT"), 
                                           col.names = c("id", "Condition", "Date/Time",
                                                         "SONA ID", "Age/Gd.", "Handedness",
                                                         "Tester", "Notes"))
head(nice_randomized_subjects)
##   id         Condition Date/Time SONA ID Age/Gd. Handedness Tester Notes
## 1  1 AV - AT - ST - SV        NA      NA      NA         NA     NA    NA
## 2  2 AV - ST - SV - AT        NA      NA      NA         NA     NA    NA
## 3  3 SV - ST - AV - AT        NA      NA      NA         NA     NA    NA
## 4  4 SV - AT - AV - ST        NA      NA      NA         NA     NA    NA
## 5  5 AT - SV - ST - AV        NA      NA      NA         NA     NA    NA
## 6  6 AT - ST - SV - AV        NA      NA      NA         NA     NA    NA

Save data frame to Word

  1. Save the resulting dataframe as a nice_table, and then to Word:
runsheet <- nice_table(nice_randomized_subjects)
save_as_docx(runsheet, path = "runsheet.docx")
# Change the path to where you would like to save it.
# If you copy-paste your path name, remember to use "R" slashes ('/' rather than '\').
# Also remember to specify the .docx extension of the file.
  1. After saving your dataframe to Word, open it in Word.

  2. Make your document horizontal by going to the Layout tab, Page Setup section, then clicking on the “Orientation” button and selecting the Landscape option.

  1. Select whole table.

  1. Left align table.

  1. Turn off preferred width in table properties.

  1. Make required formatting arrangements: In the Home tab, Paragraph section, click on the Borders button, then click All Borders.

  1. Next adjust the columns width to fit your page (especially the “Notes” column, which should be wider).

  1. If necessary, pull the table left with the little square pound Move Table Column button in top margin to create more space (note that the table should be selected first).

  1. Double-click on the header to edit it and add a title (e.g., “Study 3 Runsheet”); center and bold (suggested font size: 14).

  1. Under the title in smaller font (not bold; suggested size: 12), add the legend for the conditions (e.g., “SV = Synchronous Visual, AV = Asynchronous Visual, ST = Synchronous Tactile, AT = Asynchronous Tactile”).

  1. Add a page number at the bottom of the page by going to the Insert tab, Header & Footer section, and click on the “Page Number” button, then selecting “Bottom of Page”, then Plain Number 3 (which is bottom right).

  1. Now ‘Save As’ using the F12 keyboard key, then select save as .pdf, and you’re done! :)

You can now use this runsheet yourself, print it, or send it to your research assistants!

Note: you might want to save that word document as you work on it to not lose it and perhaps reuse it in the future!

Thanks for checking in

Make sure to check out this page again if you use the code after a time or if you encounter errors, as I periodically update or improve the code. Feel free to contact me for comments, questions, or requests to improve this function at https://github.com/rempsyc/rempsyc/issues. See all tutorials here: https://remi-theriault.com/tutorials.