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.

Loading

Comments

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

  1. M.A. Claassen Avatar
    M.A. Claassen

    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. ryan Avatar

      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. giulia Avatar
    giulia

    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. juliana Avatar
    juliana

    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. Fiona Avatar
    Fiona

    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. Chris Avatar

    I also had some issues that the random variable was regenerated on each page.

    In the forum (https://www.limesurvey.org/forum/design-issues/82187-problems-randomising-survey-using-rand) I found the following solution:

    {if(random>0,random,rand(1,3))}

    Now the value of random stays the same over the different groups and pages.

  6. Beth Avatar
    Beth

    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. Beth Avatar
      Beth

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

  7. Kari Avatar
    Kari

    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

  8. Sette beste typ Avatar
    Sette beste typ

    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 😀 )
    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. Sette beste typ Avatar
      Sette beste typ

      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 !!

    2. Pavol Avatar
      Pavol

      THIS actually helped!

      Thanks

  9. Florian Avatar
    Florian

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

    1. ryan Avatar

      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.

      1. Florian Avatar
        Florian

        Thanks a lot!

  10. Hanzie Avatar
    Hanzie

    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!

  11. Rexa Avatar
    Rexa

    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. ryan Avatar

      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.

  12. Marcel Minke Avatar

    The newer Limesurvey versions (>= 3.x) support various randomization features. We have outlined them at https://survey-consulting.com/how-to-randomize-items-at-limesurvey/

    1. Daniel Avatar
      Daniel

      For me it doesn’t work!

      I do have a “random dummy group” with the code “random1” prior to the experimental part. It is an “equation” question with the code {rand(1,6)}. Afterwards there’s the experimental group with six stimuli (4 experimental groups, 2 without stimuli as control groups). They all have the code ((random1==3)) (or 4, 5, 6 etc) in the Relevance equation. If I preview the group the randomization works like a charm, though if I want to preview the entire survey this experimental part does never appear. the survey just skips the part and shows the first questions after the experimental question group. What am I missing?

  13. Daniel Avatar
    Daniel

    Hi there,

    I did everything and it worked like a charm right until I went through the survey in preview. Instead of showing me one of the 6 randomized stimuli, it skipped the experimental part all together and showed the next question after the randomized items… What happened? Do I have to put something into the “relevanze equation” of the initial “random”-dummy question?

    Thank you for your help

  14. Sarah Avatar
    Sarah

    Hi! Many thanks for this post.

    I am creating a survey and I have 2 conditions. I only want to split the participants into one of two conditions for one part of the survey (I have created one question group with the questions I want group A to answer and another for group B).

    I understand that I must include the equation ((random==1)) and ((random==2)) in the ‘relevance equation’ box for the question groups specific to group A and B respectively.

    However, for the other question groups which I want all participants to answer (irrespective of the randomly assigned group), must I put an equation in the ‘relevance equation’ stating that I want both random 1 and random 2 to answer?

    Hope my question makes sense! Thanks in advance!

    1. rcragun Avatar
      rcragun

      If you don’t put anything in the relevance equation box, the questions should be shown to everyone.

  15. Sarah Avatar
    Sarah

    Hi everyone,
    I have created the hidden first question in order to then randomly assign participants to one of two conditions ({rand(1,2)}.
    However, as I have already set a condition (for all questions) to ensure that they can only respond if they have given their consent at the beginning of the questionnaire, it tells me that I cannot edit the relevance equation as I have already set out conditions. This is where I would have to type in ((random==1)) or ((random==2)).
    Is there a way of adding this relevance equation elsewhere? In the “set conditions” menu for example?
    Many thanks,
    Sarah

    1. rcragun Avatar
      rcragun

      Hi Sarah,

      An easier approach would be to:

      (1) Remove the condition you have on all the questions about consent.
      (2) Instead, set up branching logic that terminates the survey if they do not consent. That will do the same thing as what you had previously done with the conditions on all the questions since they will not be able to answer any questions if they do not consent.
      (3) Then set up the condition I described in the post.

  16. cheri Avatar
    cheri

    Hi I still do not understand how it works.
    I have 2 question groups and would like to show 1 question group randomly for people to complete.
    How should I make it work?

    Thanks a lot.

    1. rcragun Avatar
      rcragun

      Follow the directions above, but change “rand(1,3)” to “rand(1,2)” for just two groups.

  17. Aaron Avatar
    Aaron

    Hi rcragun,
    Thanks for the very clear explanation. I’m using LimeSurvey Community Edition Version 6.2.1+230807, and I can’t see “Relevance equation” within any question or group.
    Is “Relevance equation” had a name change to “Condition” (under question ‘General Settings’) or “Randomization group name” (under question ‘Logic’)?
    Thanks again.

    1. rcragun Avatar
      rcragun

      Unfortunately, I no longer use Limesurvey. Hopefully, someone else can answer your question.

Leave a Reply

Your email address will not be published. Required fields are marked *