Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Randomizing subjects evenly between conditions

  • Herrasmies
  • Herrasmies's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
9 years 1 month ago - 9 years 1 month ago #116563 by Herrasmies
Greetings!

I’m a new LimeSurvey user (version 2.05+ Build 141113). I’m designing a psychological experiment where participants are randomized into one of 8 different conditions. Each condition contains the same questions, but participants will be “manipulated” in a different way (e.g., different background colour etc.).

My problem is how to randomize participants evenly between these 8 conditions. Going through the manual and searching for pre-existing threads has helped me get as far as this:

I have created an equation-type question {rand(1, 8)} that is always hidden. After that the following questions are conditionally shown based on the value of the random number: questions in condition 1 are shown if rand(1, 8) = 1, etc.

The randomization works, but, as expected, isn’t evenly distributed between the conditions. I need 70 participants per condition (or as close as possible to this). I thought about working around this by changing the rand() parameters “on the go” – i.e., when one condition gets the needed 70 participants, I could switch the rand() parameters to exclude that condition. However, this seems a bit cumbersome: if, e.g., condition "5" is the first to get the 70 participants, then how to exclude number "5" from the rand() -function?

Another way I thought of was including a code that randomly picks a number from an array (i.e., array of 1, 2, 3, 4, 5, 6, 7, 8), and I would just edit that array "on the go", but lacking background in programming, I'm not sure how to do that either.

Sincerely appreciating your help,
Jussi Palomäki

p.s. the word "condition" is not in reference to the LimeSurvey term, despite being hyperlinked
Last edit: 9 years 1 month ago by Herrasmies.
The topic has been locked.
  • fransmarcelissen
  • fransmarcelissen's Avatar
  • Offline
  • Premium Member
  • Premium Member
More
9 years 1 month ago #116574 by fransmarcelissen
Replied by fransmarcelissen on topic Randomizing subjects evenly between conditions
Often there are smart solutions and simple solution. The simple solution here is to do the randomization externally and read it in into a token attribute. Then you do'nt need the hidden question anymore.
In addition: you use an equation question with a rand(). The problem with this is that rand() is evaluated again and again, each time with a different result. It is simpler to use a hidden text field and set the default value to rand(). Now the expression is executed only once en keeps its value.
Succes
Frans
The topic has been locked.
  • Herrasmies
  • Herrasmies's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
9 years 1 month ago - 9 years 1 month ago #116578 by Herrasmies
Replied by Herrasmies on topic Randomizing subjects evenly between conditions

fransmarcelissen wrote: Often there are smart solutions and simple solution. The simple solution here is to do the randomization externally and read it in into a token attribute. Then you do'nt need the hidden question anymore.
In addition: you use an equation question with a rand(). The problem with this is that rand() is evaluated again and again, each time with a different result. It is simpler to use a hidden text field and set the default value to rand(). Now the expression is executed only once en keeps its value.
Succes
Frans


Thanks for your response!

I don't fully understand, however. I might've been unclear in my first post.

Currently, the rand() does seem to work well insofar as participants are correctly randomised into different conditions (or "groups"), and each participant sees only those questions that belong to that specific condition. So the rand() -value does not change for a single participant.

The problem is that the distribution of participants per condition will very likely be uneven. I'd like 70 participants in each condition/group, but could end up with, e.g., 40, 90, 77, 65, 55, 67, 50, 69, for conditions/groups 1-8, respectively. How to control this distribution of participants is my main concern. I guess this can't be done with rand()? The way this could be done is to have a function that randomly picks between an array of pre-set numbers -- and I'd just edit this array on the go (e.g., I start with an array of 1,2,3,4,5,6,7,8, and when group 5 is "full", I change the array into 1,2,3,4,6,7,8).

Thanks for your help!

-Jussi
Last edit: 9 years 1 month ago by Herrasmies.
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 1 month ago #116583 by holch
How are your respondents invited? Is the survey open or do you invite them via email and could use token.

If you use token, Frans had a very good suggestion by using a token table with the numbers from 1-8 already applied to the list of participants.

When you have a survey were anyone can just access a link, then you probably have a problem...

You could use quota and close the survey for those that have been assigned a number from 1-8 that has already reached the n=70, but that means that this respondent will not be able to continue in the survey, so you lose this respondent (might might not be desireable).

I guess you won't get around some manual ajustments or custom programming (put a script before your survey that will assign random numbers and then at the end-url you pass the applied number to the script, that will register the number of completed surveys with that number and stop using it among the random assignment. But as I said, this will involve quite some custom programming.

But if you have quite a big pool of respondents and have no worries to get the survey completed with more than enough respondents, I guess I would go for the simple solution: Let the survey run until the first have passed 70 and then adapt the random script and the conditions/expression accordingly, so that only the other paths will be chosen from then on. Needs some manual work, but if you are lacking the ability of writing custom scripts, I guess it is your best way, if you have a open survey. With token based surveys the randomizatin could be done beforehand in the tokentable as Frans suggested. That would be the easiest solution I guess.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
More
9 years 1 month ago #116586 by amygdalafreud
Replied by amygdalafreud on topic Randomizing subjects evenly between conditions
I have a similar issue and I was about to make a thread about it when I saw this one. In my case, I have five different sets of questions ("conditions") for which I want fifteen participants each only. The survey won't be attempted by the general public and I'd control who gets the link and who doesn't, but how do I use tokens in such a scenario to create five discrete kinds of tests? What other features can be manipulated (e.g. quotas) in order to produce the same effect? Programming isn't my forte in the least, so any detailed but doable solution would be very much appreciated.
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 1 month ago #116589 by holch
@amygdalafreud:

You would create one big survey with all the different sets of question. Then you use expressions (or conditions, but I recommend to use expressions, once you get it, it is so much quicker).

If you are tokens, you can create a custom attribute in the token table and give a random number from 1-5 to the respondents. Within Limesurvey you can use the custom attribute within the expressions to show/hide questions, depending on the value of this custom attribute, just as you would do with the random number generated within Limesurvey. So your case should be quite simple and won't need any custom scripts. You just need to understand how tokens work and how you can hide/show questions via expressions (or conditions).

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 1 month ago - 9 years 1 month ago #116631 by tpartner
Replied by tpartner on topic Randomizing subjects evenly between conditions
@Herrasmies, following up on your idea to "randomly pick between an array of pre-set numbers", here is a JavaScript solution to do that...

Place the following script in the source of a short-text question and modify the array on line 5 as required. The script will:
- Hide that question
- "Shuffle" (randomize) the array
- Load the first value of the shuffled array into the question

This effectively lets you remove numbers from the randomized set as the survey progresses.

Code:
<script type="text/javascript" charset="utf-8">  
  $(document).ready(function() {
 
    // The array of numbers to be randomized
    var conditionNumbers = [1, 2, 3, 4, 5, 6, 7, 8]; 
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
 
    // Hide this question
    thisQuestion.hide();
 
    // Shuffle the array
    conditionNumbers = $.shuffle(conditionNumbers);
 
    // Load the first array value into this question
    if($.trim($('input.text', thisQuestion).val()) == '') {
      $('input.text', thisQuestion).val(conditionNumbers[0]);
    }
  });  
 
  // A function to shuffle elements or contents of arrays
  (function($){
    $.fn.shuffle = function() {
      return this.each(function(){
        var items = $(this).children();
        return (items.length)
          ? $(this).html($.shuffle(items))
          : this;
      });
    }
 
    $.shuffle = function(arr) {
      for(
        var j, x, i = arr.length; i;
        j = parseInt(Math.random() * i),
        x = arr[--i], arr[i] = arr[j], arr[j] = x
      );
      return arr;
 
    }
  })(jQuery);
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 9 years 1 month ago by tpartner.
The topic has been locked.
  • Mazi
  • Mazi's Avatar
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
9 years 1 month ago #116639 by Mazi
In the long run we are planning to make the quota feature more flexible and connect it to the Expression Manager features and functions.
That may also be a good option to combine the quota feature of checking the number of current responses to certain questions with a feature for equally distributing people.

Maybe this is worth a feature request...?!

Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The topic has been locked.
  • Herrasmies
  • Herrasmies's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
9 years 1 month ago #116699 by Herrasmies
Replied by Herrasmies on topic Randomizing subjects evenly between conditions
Hi again,

Thank you everyone! I sincerely appreciate the help and information. Since I will be using Amazon mTurk to invite participants, using tokens will be problematic. However, the javascript offered by tpartner will work perfectly for me!

Thanks again,
Jussi
The topic has been locked.
  • Mazi
  • Mazi's Avatar
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
9 years 1 month ago - 9 years 1 month ago #116700 by Mazi
You're welcome :-)

If our hints have been helpful and you enjoy Limesurvey please donate to give LimeSurvey a future.

We do all this in our free time and you don't have to pay a penny for this software.

Without your help we can't keep this project alive.

Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
Last edit: 9 years 1 month ago by Mazi.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose