2 min read

Tutorial: How to randomize in R

Tutorial: https://learn.themethodsection.com/tutorial/randomize

Source: Github


I teach a class session on experimental designs, and in my prep this week I was looking for a brief activity that would give students an opportunity for hands-on learning. In the process of searching the web for inspiration, I had a flashback to early RA days where I was asked to randomize participants into groups and had no idea how to do it for real.

I remembered seeing something recently about randomization in the Declare Design suite of tools, so I headed over to the site and found the randomizr package for R. The site includes a tutorial that incorporates another randomization package I know called blockTools, so I had the basis for a tutorial idea.

There are several great options for creating interactive tutorials. Ines Montani developed a Binder-based framework for her spaCy course that she adapted for R users. Karthik Ram created holepunch for turning R notebooks into interactive RStudio instances with your project and all its dependencies.

I decided to go with RStudio’s learnr package for creating interactive tutorials. It’s easy to use and I think the layout is intuitive for learners.

The tutorial I created shows you how to use several randomizr functions to randomize individuals and clusters to study arms with and without blocking. Learnr lets you change the code and see what happens without having to spin up your own instance, which I think is key for students who don’t have a background in R. It’s a great platform for sparking interest in statistical programming.