Limesurvey: How to Randomly Assign Participants to Different Conditions (i.e., Experimental Designs)

I’ve used LimeSurvey for a long time and really like the software.  It’s powerful, yet very easy to use.  But one thing I couldn’t figure out with the software was how to assign participants to one of several conditions within a single survey.  For example, if you want to randomly assign participants in your survey to one of three groups and one of those groups will see some intervention, another group will see a different intervention, and the third group will see a control condition, as in an experimental design, I couldn’t figure out how to do that before.  Turns out, it is possible.  I found this tutorial that explained it, but it wasn’t all that clear, so I’m creating a tutorial here to make it very clear how this works.

What I wanted to do is like the hypothetical scenario I described above.  I am conducting a survey and have two experimental conditions; participants are going to read one of two vignettes that are designed to influence them in specific ways and one control condition in which the vignette is designed not to influence participants in any way.  I want to randomly assign every person who takes the survey to one of these three conditions so they only see one of the three vignettes.  Here’s how you do this.

First, you have to create a variable in LimeSurvey that randomly assigns each participant to one of the groups.  This should basically be the first variable in your survey.  But, the key is that you don’t let participants see the variable.  So, you add a new question to your first Question group:

limesurvey1

You can name that variable whatever you want (this goes in the Code: box), but I named mine “random.”

limesurvey2

Then, you need to choose the type of question.  Go down to where it says “Question type:” and select “Equation”:

limesurvey3

The equation itself goes in the “Question:” box, like this:

limesurvey4

The equation you use is the following:

{rand(1,3)}

What this equation tells LimeSurvey to do is to select a random number between 1 and 3 (the two values in the parentheses) and assign that to this particular participant (if you have more conditions, you can increase the number of groups by increasing the second integer – i.e., change 3 to 4, 5, 6, etc.).

You have to do one more thing before you’re done creating the question.  Go down to “Show advanced settings” and click on it.  It will open the advanced settings options.  Scroll down to where it says, “Always hide this question” and select “Yes” from the drop down menu.  This tells LimeSurvey that you don’t want participants to see this question. Once you’ve done that, click on “Save” and you’ve now created the variable that randomly assigns participants to one of the three conditions.

limesurvey5

You’ve finished the hard part.  Now you have to tell LimeSurvey which variables go with which randomly assigned numbers and their corresponding conditions.  You do this while creating the questions.  So, start creating the questions you want the participants in each of the groups or conditions to see (these should obviously be in a later question group than the above question, or the branching won’t work).  While creating the question, scroll down to where it says, “Relevance equation”.  In that box is where you’re going to add the necessary code to assign each question to a randomly assigned condition.  The code you’ll use is the following:

  • for those assigned to condition 1, add to that box: ((random==1))
  • for those assigned to condition 2, add to that box: ((random==2))
  • for those assigned to condition 3, add to that box: ((random==3))

It should look like this:

limesurvey7

Once you’ve added the Relevance equations and hit “Save”, now you can test the survey.  You should be randomly assigned to a different condition each time and see only the questions that meet the relevance equation criteria – meaning, if you were randomly assigned to condition 1, you’ll only see the questions assigned to that condition, ditto with condition 2 and condition 3.

And there you have it – you have created a survey that includes random assignment to different conditions.

17 Replies to “Limesurvey: How to Randomly Assign Participants to Different Conditions (i.e., Experimental Designs)”

  1. Thank you for the tutorial. I want to suggest the following correction: when assigning the conditions in ‘Relevance equation’, the code used should be:

    for those assigned to condition 1, add to that box: ((random==1))

    The condition number should not be surrounded by quotation marks, it gave me an error.

    1. M.A. Claassen,

      Thanks for the information. The quotations worked for me, but if they aren’t necessary, that’s even simpler. I’ll remove them from the tutorial. Thanks for the suggestion.

  2. your explanations are perfect, but, why it doesen’t work, when I do IT?
    I can’t understand whats wrong, i follow exactly every passage.

    My hidden question is in a group.
    And Just after there are the 4 groups i want to randomize. Every group have is code, written like u tell.

    i’m kind of lost, if u can help me, i’ll be gratefull

  3. Thank you for your great explanation.
    I want to randomly assigned participants to two different conditions (A and B). As you explained, I already have done the procedure indicated by you. However, now I need to randomly assign the participants of the condition A to two different conditions (A1 and A2). Do you think that this is possible?
    I will be grateful if you can give some help.
    Thank you

  4. This doesn’t work for me … I think I did everything you said. The “random” from ((random==1)) is surrounded by a red square (meaning this isn’t working). I started creating a new group of questions for the random. Then an other group for my conditions (I have 4). Was that wrong?

  5. Hi there Ryan, thankyou SO MUCH for this – it was really helpful and provided a key part of the structure of my survey!

    I’m just wondering if you might also know how to enable a save and return function when questions are randomly allocated in this way?

    My understanding is that when using the ‘resume later’ / ‘save and return’ feature this undoes any randomisation because the randomisation is generated afresh each time you log on. However, I am wondering if tokens can overcome this? ie when a participant is allocated a token, does that ‘freeze’ the particular survey generated for them so when they log in at a later time they will still be allocated to the same randomisation stream and be able to pick up with the same set of questions at the same point where they logged out earlier?

    Thanks again so much,

    Beth

    1. PS Sorry I don’t know why my name generated an angry looking cartoon icon! Complete accident – I’m not angry at all!! :) :) :)

  6. Thanks for this post, it’s really helpful. I’m struggling to get my randomly assigned conditions to appear – at the moment my study skips straight to the second part (which is for all participants). I followed the above instructions, adding a new question group at the beginning for my ‘random’ questions, then adding the appropriate equations ( ((random==1)) etc.) to all my condition questions. I don’t think it’s an issue with the ‘random’ question itself, as that shows up fine on the test when I don’t automatically hide it. The only thing I can think is that I should have created different question groups for each of the conditions – would this make a difference? Any help much appreciated! Thanks, Kari

  7. Guys its pretty simpel:

    if u go with the normal equation : {rand(1,2)} u will get 1 or 2 and that is for the Question with the code:random (FOR EXAMPLE)

    so in the question for 1 u fill in
    Relevance equations: random==1
    (IT MUST BE THE NAME OF THE CODE THAT U GAVE so its “random” here )

    if u go the other way with the equation:
    {if(random>0,random,rand(1,2))} “random” is the name of the variablecode so if its different for you it will get a red mark around (maybe u named it random1 or randnumber or butterfly i dont know :D )
    just replace it then in the equation and later in the Relevance equations…

    code:butterfly
    {if(butterfly>0,butterfly,rand(1,2))}

    for Q1: Relevance equations:butterfly==1

    UR WELCOME

    1. if u go with the normal equation : {rand(1,2)} u will get 1 or 2 and that is for the question with the Equation in it —>here with the variablecodename code:random (FOR EXAMPLE) like did in the example above on the page !!

  8. Hello, will it be possible to see in the statistics which participant was assigned to which group?
    Thanks

    1. Florian, yes you will see which participant was assigned to which group. They are assigned a number by the software, which makes it easy to tell who has been assigned to which group.

  9. Okay this took me forever to figure out but it might be helpful for others: the program is sensitive to capital letters. So I had the codename “Random” and then used the equation ((random==1)) etc. and it kept giving me errors. I then changed it to “random” (no capitals so the same as in the equation) and then it magically worked!

  10. Hello, thank you for this great post.

    I would like to know how to make it work in my situation, the Group A and B i want them to show always first in this specific order then i have a third group (C) that evritime one respondent gets here i want to present him one of nine possible set of questions.

    This because initially i was thinking to do nine different version of my questionaire just to randomize Group C set of questions. But if i can do that based in the logic u present here would be great for me, while divulgating the survey (since instead 9 links i could just show one link).

    1. Rexa,

      I may not be understanding the situation exactly, but here’s my best guess. Rather than nine different versions of your survey, I’d make three. One survey for Group A. One survey for Group B. And one survey for Group C. For the Group C survey, use the random assignment procedure detailed in this post. That should do what you need.

      If you wanted to get creative, you could try doing it all in one survey. I don’t know if it is possible to nest random assignment within a survey as I haven’t tried it (i.e., have one random assignment variable at the beginning and then another later). Theoretically, it would be possible to do all of this in one survey, but it would require some more complex survey logic. You could try it, but I think the easiest approach would be to create three separate surveys.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.