Check out the LimeSurvey source code on GitHub!
Welcome, Guest
Username: Password:

TOPIC: Random assignment to conditions

Random assignment to conditions 2 years 10 months ago #103895

  • hutzel
  • hutzel's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 1
  • Karma: 0
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:
    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 administrator has disabled public write access.

Random assignment to conditions 2 years 10 months ago #103910

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6575
  • Thank you received: 1477
  • Karma: 579
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 administrator has disabled public write access.

Random assignment to conditions 2 years 10 months ago #104088

  • MarcellavZ
  • MarcellavZ's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 13
  • Karma: 0
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 administrator has disabled public write access.

Random assignment to conditions 2 years 10 months ago #104094

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6575
  • Thank you received: 1477
  • Karma: 579
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:
<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: 2 years 10 months ago by tpartner.
The administrator has disabled public write access.

Random assignment to conditions 2 years 10 months ago #104096

  • MarcellavZ
  • MarcellavZ's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 13
  • Karma: 0
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 administrator has disabled public write access.

Random assignment to conditions 2 years 10 months ago #104137

  • LBOATENG10
  • LBOATENG10's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 3
  • Karma: 0
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 administrator has disabled public write access.

Random assignment to conditions 2 years 10 months ago #104155

  • Hendrik01
  • Hendrik01's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 9
  • Karma: 0
Hi Tony,

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

I also tried all kinds of variations:
{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 administrator has disabled public write access.

Random assignment to conditions 2 years 10 months ago #104159

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6575
  • Thank you received: 1477
  • Karma: 579
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 administrator has disabled public write access.
The following user(s) said Thank You: Hendrik01

Random assignment to conditions 2 years 10 months ago #104165

  • Hendrik01
  • Hendrik01's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 9
  • Karma: 0
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 administrator has disabled public write access.

Random assignment to conditions 2 years 10 months ago #104173

  • Hendrik01
  • Hendrik01's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 9
  • Karma: 0
Also be aware that the modulo function (%) doesn't work yet.
You'll have to use
{SAVEDID - (floor(SAVEDID/4)*4) + 1}
.
Last Edit: 2 years 10 months ago by Hendrik01. Reason: typo
The administrator has disabled public write access.

Random assignment to conditions 2 years 10 months ago #104175

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6575
  • Thank you received: 1477
  • Karma: 579
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 administrator has disabled public write access.

Random assignment to conditions 2 years 8 months ago #107099

  • zboy
  • zboy's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 9
  • Karma: 0
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 administrator has disabled public write access.

Random assignment to conditions 2 years 6 months ago #109707

  • fiona92
  • fiona92's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 2
  • Karma: 0
tpartner wrote:
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:
<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>

.

I don't know where to fill in this script?
After the first page submission.... So after the first question is filled in, by the second question fill in this script? Of by the first question, after the page with welcome and intructions? And how do i make the different questionaires for the three groups?
The administrator has disabled public write access.

Random assignment to conditions 2 years 6 months ago #109735

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6575
  • Thank you received: 1477
  • Karma: 579
After the first page submission.... So after the first question is filled in, by the second question fill in this script?
Place the script in the source of a short-text question on a page AFTER the first QUESTION PAGE has been submitted.



And how do i make the different questionaires for the three groups?
See conditions or relevance - manual.limesurvey.org/Setting_conditions.


.
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last Edit: 2 years 6 months ago by tpartner.
The administrator has disabled public write access.

Random assignment to conditions 1 year 8 months ago #118648

  • esyild
  • esyild's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 4
  • Karma: 0
I need your help.

I have two different questions and I want the survey tool to show one question at a time randomy. I want to assign my participants to the survey randomly. That is why I used the equation question type with rand(1,2) function. The test survey works perfectly. But when I activate it, it stuck on one condition and only shows the same question for everytime.

Do you know why it happened??

Thanks a lot.

Kind Regards,
The administrator has disabled public write access.
Time to create page: 0.278 seconds
Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form