Check out the LimeSurvey source code on GitHub!

Random assignment to conditions

More
3 years 2 days ago #103895 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:
    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?

Please Log in to join the conversation.

More
3 years 2 days ago #103910 by tpartner
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.

Please Log in to join the conversation.

More
2 years 11 months ago #104088 by MarcellavZ
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!

Please Log in to join the conversation.

More
2 years 11 months ago - 2 years 11 months ago #104094 by tpartner
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 11 months ago by tpartner.

Please Log in to join the conversation.

More
2 years 11 months ago #104096 by MarcellavZ
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!

Please Log in to join the conversation.

More
2 years 11 months ago #104137 by LBOATENG10
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

Please Log in to join the conversation.

More
2 years 11 months ago #104155 by Hendrik01
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

Please Log in to join the conversation.

More
2 years 11 months ago #104159 by tpartner
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

Please Log in to join the conversation.

More
2 years 11 months ago #104165 by Hendrik01
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.

Please Log in to join the conversation.

More
2 years 11 months ago - 2 years 11 months ago #104173 by Hendrik01
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 11 months ago by Hendrik01. Reason: typo

Please Log in to join the conversation.

More
2 years 11 months ago #104175 by tpartner
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.

Please Log in to join the conversation.

More
2 years 9 months ago #107099 by zboy
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.

Please Log in to join the conversation.

More
2 years 7 months ago #109707 by fiona92

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?

Please Log in to join the conversation.

More
2 years 7 months ago - 2 years 7 months ago #109735 by tpartner

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 7 months ago by tpartner.

Please Log in to join the conversation.

More
1 year 9 months ago #118648 by esyild
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,

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form