Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: Random assignment to conditions

Random assignment to conditions 7 months 6 days 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 7 months 6 days ago #103910

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4127
  • Thank you received: 761
  • Karma: 347
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Random assignment to conditions 7 months 3 days 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 7 months 3 days ago #104094

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4127
  • Thank you received: 761
  • Karma: 347
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Last Edit: 7 months 7 hours ago by tpartner.
The administrator has disabled public write access.

Random assignment to conditions 7 months 3 days 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 7 months 19 hours 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 7 months 10 hours ago #104155

  • Hendrik
  • Hendrik'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 7 months 7 hours ago #104159

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4127
  • Thank you received: 761
  • Karma: 347
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
The following user(s) said Thank You: Hendrik

Random assignment to conditions 7 months 6 hours ago #104165

  • Hendrik
  • Hendrik'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 7 months 5 hours ago #104173

  • Hendrik
  • Hendrik'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: 7 months 5 hours ago by Hendrik. Reason: typo
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.353 seconds
Donation Image