Welcome to the LimeSurvey Community Forum

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

Random assignment to conditions

  • hutzel
  • hutzel's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 1 month ago #103895 by hutzel
Random assignment to conditions was created by hutzel
Hello everyone,

is it possible in Limesurvey to get a random assignment to different conditions (like control /experimental group)? It should be a equal distribution as possible.

Until today i did it with a javascript code like this:
Code:
    var min = 0;
    var max = 3;
 
 
     var random = Math.floor(Math.random() * (max - min + 1) + min);
 
    $('#question1234').hide();
    $(document).ready(function() { 
    document.getElementById('answer1234X123X12').value = random;
    });

I produced a random number and put it as an answer for a hidden question, so I can refer to this answer later.

But is there a better way to do this?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 1 month ago #103910 by tpartner
Replied by tpartner on topic Random assignment to conditions
You can use Expression Manager to load an equation type question with a random number - manual.limesurvey.org/Expression_Manager...e_Question_Per_Group

.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
10 years 1 month ago #104088 by MarcellavZ
Replied by MarcellavZ on topic Random assignment to conditions
Hello,

I have a similar question. In my survey I have 4 conditions. Via a hidden question ({rand(1,4)}) and linking each question that belongs to one of the 4 conditions through 'token, previous question, value equals ...' my survey already randomly assigns participant to one of the four conditions but that doesn't happens equally. For example, I want that 40 participants are assigned to condition a, 40 participant to condition b ans so on. The technical department of my university says that it isn't possible via Limesurvey so now I have come to you.. I hope that there is a solution, otherwise I think that the only possibility is to manual assign people to one of the conditions with their email address in advance.. Javascript is really a different language for me so please help me.

Thanks!
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 1 month ago - 10 years 1 month ago #104094 by tpartner
Replied by tpartner on topic Random assignment to conditions
Well, you can use the {SUBMITID} variable (which is available AFTER the first page submission) and the JavaScript modulus operator to load a hidden short-text question with sequential numbers between 1 and 4.

Note though, that the sequential number will increment with every respondent, even those who don't complete the survey.

Add this script to the source of a short-text question:
Code:
<script type="text/javascript" charset="utf-8">  
 
  $(document).ready(function() { 
 
    var submitID = {SAVEDID};
 
     // Hide this question
    $('#question'+qID).hide();
 
    // Find sequential number between 1 and 4 based on the SUBMITID
    var conditionNumber = (submitID % 4) + 1;
 
     // Load the hidden question
    $('#question'+qID+' input.text').val(conditionNumber);
  });
</script>

.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 10 years 1 month ago by tpartner.
The topic has been locked.
More
10 years 1 month ago #104096 by MarcellavZ
Replied by MarcellavZ on topic Random assignment to conditions
Hi Tony,

Thank you! I will try to implement what you have said in my survey. I'm sure it works, now I only need to make it work with my technical skills... I will try. Thanks!
The topic has been locked.
More
10 years 1 month ago #104137 by LBOATENG10
Replied by LBOATENG10 on topic Random assignment to conditions
Hello,

I also have a similar issue. I am conducting an on-line research with 12 conditions. I would like each condition to have 15 participants. Thus, can someone please provide me step-by-step instructions on how to set that up; I am new to Lime Survey and to the world of coding.

Thank you,

Lois
The topic has been locked.
More
10 years 1 month ago #104155 by Hendrik01
Replied by Hendrik01 on topic Random assignment to conditions
Hi Tony,

Thank you for this answer it looks useful, except...
I tried
Code:
{SUBMITID}
which results in "unknown variable".

I also tried all kinds of variations:
Code:
{SUBMIT_ID} {SUBMITID} {Submitid} {SubmitId} {SubmitID} {SUBMID} {QID}
All of the SUBMITID variations give the error, while QID shows up valid.

This is in a question in the second group, so it should be available, right?

Do you have any idea what I am doing wrong here?
I am using LS 2.00+ Build 131206

Thanks for any help,
Kind regards,
Hendrik Jan
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 1 month ago #104159 by tpartner
Replied by tpartner on topic Random assignment to conditions
Oops, sorry, I meant {SAVEDID} :blush:

(Note that it is only available after the first question page is submitted)

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: Hendrik01
The topic has been locked.
More
10 years 1 month ago #104165 by Hendrik01
Replied by Hendrik01 on topic Random assignment to conditions
Thank you; {SAVEDID} works.

For anybody else reading this; {SAVEDID} is only useful on an active survey, on an inactive suvey it only returns an empty string.
The topic has been locked.
More
10 years 1 month ago - 10 years 1 month ago #104173 by Hendrik01
Replied by Hendrik01 on topic Random assignment to conditions
Also be aware that the modulo function (%) doesn't work yet.
You'll have to use
Code:
{SAVEDID - (floor(SAVEDID/4)*4) + 1}
.
Last edit: 10 years 1 month ago by Hendrik01. Reason: typo
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 1 month ago #104175 by tpartner
Replied by tpartner on topic Random assignment to conditions
Yes, that's why I used JavaScript.

.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
9 years 11 months ago #107099 by Moeontri_38918
Replied by Moeontri_38918 on topic Random assignment to conditions
Hi guys,

I would like to use the code posted on the first page but I can't get it working. Do I need to change anything in it like the qID or something like that?

Thanks.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose