Welcome to the LimeSurvey Community Forum

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

Multiple choice question: split up randomly

  • gsoto
  • gsoto's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 11 months ago #197999 by gsoto
For a survey, I have a list of 50 items that I want to test in a multiple choice question. However, because a question with 50 items is overwhelming for the participants, I want to split the items in three questions. The assignment of the items to the three questions should be random.

I have an approach that is based on the "randomly show x out of n questions" approach:
  1. In a first question group, create three randomization groups. Each randomization group contains a question (let's call it "grouping question") for every item.
  2. Randomly draw x questions from each group using sum(q.relevanceStatus, …) LT x
  3. In a second question group, create three multiple choice questions with all items
  4. Use the relevance status of the "grouping questions" in the first question group as the relevance equation for the individual items

I have attached an example with 5 items that shows how it works.

This does work, however for 50 items, it means setting up 150 questions to do the random drawing in the first question group and having an individual relevance equation for every single question.

Is there a simpler way to get the result? I have tried using the "randomly show x out of n questions" approach on the subquestions of a multiple choice group. This way, I would only need three multiple choice questions to do the random grouping in the first question group, rather than 150 individual questions. However, this always gives me the same x subquestions rather than a random draw.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 11 months ago - 3 years 11 months ago #198005 by Joffm
Hi, gsoto,
here a different approach.
First create a question of type "short text". Let's call it "Q1".
By a small javascript snippet you create a random order of 50 numbers
Code:
<script type="text/javascript" charset="utf-8">
 
function shuffle(array) {
  var currentIndex = array.length, temporaryValue, randomIndex;
 
  // While there remain elements to shuffle...
  while (0 !== currentIndex) {
 
    // Pick a remaining element...
    randomIndex = Math.floor(Math.random() * currentIndex);
    currentIndex -= 1;
 
    // And swap it with the current element.
    temporaryValue = array[currentIndex];
    array[currentIndex] = array[randomIndex];
    array[randomIndex] = temporaryValue;
  }
 
  return array;
}
 
 
$(document).on('ready pjax:scriptcomplete',function(){
// Fill the array
      var arr =["01","02","03","04","05","06","07","08","09",10, 11,12,13,14,15,16,17,18,19,20, 21,22,23,24,25,26,27,28,29,30, 31,32,33,34,35,36,37,38,39,40, 41,42,43,44,45, 46,47,48,49,50];
 
  arr = shuffle(arr);
      anumbers = '#,' + arr.join(',')+ ',';
$('#question{QID} input[type="text"]').val(anumbers).trigger('keyup');  
 
//  Uncomment this to hide the question
//      $('#question{QID}').hide();
   });
</script>

You will get this:


Now you can use subquestion relevance to show your three questions with 17, 17 and 16 items.
For the first 17 items the subquestion relevance is:
strpos(Q1,',01,')<51
strpos(Q1,',02,')<51
...
strpos(Q1,',50,')<51

For the second 17 items the subquestion relevance is:
strpos(Q1,',01,')>51 AND strpos(Q1,',01,')<102
strpos(Q1,',02,')>51 AND strpos(Q2,',02,')<102
...
strpos(Q1,',50,')>51 AND strpos(Q1,',50,')<102

And the last 16 items the subquestion relevance is:
strpos(Q1,',01,')>102
strpos(Q1,',02,')>102
...
strpos(Q1,',50,')>102

Example with only 12 items in total (3x4)

Last item not in screenshot because of screen size.

Survey

File Attachment:

File Name: limesurvey...7373.lss
File Size:44 KB



Have a look

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 3 years 11 months ago by Joffm.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 11 months ago #198008 by Joffm
An addition that might make the subquestion relevance a bit easier.

Use a question of type "multiple short text" with three subquestions to store the values
and this script
Code:
<script type="text/javascript" charset="utf-8">
 
function shuffle(array) {
  var currentIndex = array.length, temporaryValue, randomIndex;
 
  // While there remain elements to shuffle...
  while (0 !== currentIndex) {
 
    // Pick a remaining element...
    randomIndex = Math.floor(Math.random() * currentIndex);
    currentIndex -= 1;
 
    // And swap it with the current element.
    temporaryValue = array[currentIndex];
    array[currentIndex] = array[randomIndex];
    array[randomIndex] = temporaryValue;
  }
 
  return array;
}
 
 
$(document).on('ready pjax:scriptcomplete',function(){
 
  var thisQuestion = $('#question{QID}');
 
// Fill the array
      var arr =["01","02","03","04","05","06","07","08","09",10,11,12,13,14,15, 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30, 31,32,33,34,35,36,37,38,39,40,41,42,43,44,45, 46,47,48,49,50];
 
  arr = shuffle(arr);
//Store the first 17 values into the first subquestion
  anumbers = '#,' + arr.slice(0,17).join(',')+ ',';
  $('input[type=text]:eq(0)', thisQuestion).val(anumbers).trigger('keyup');
//Store the second 17 values into the second subquestion
  anumbers = '#,' + arr.slice(17,34).join(',')+ ',';
  $('input[type=text]:eq(1)', thisQuestion).val(anumbers).trigger('keyup');
//Store the last 16 values into the third subquestion
  anumbers = '#,' + arr.slice(34,50).join(',')+ ',';
  $('input[type=text]:eq(2)', thisQuestion).val(anumbers).trigger('keyup');
 
//      $('#question{QID}').hide();
   });
</script>

Then the subquestion relevance for your three questions is
1st.:
strpos(Q1_SQ001,',01,')>0
strpos(Q1_SQ001,',02,')>0
...
strpos(Q1_SQ001,',50,')>0

2nd.:
strpos(Q1_SQ002,',01,')>0
strpos(Q1_SQ002,',02,')>0
...
strpos(Q1_SQ002,',50,')>0

3rd.:
strpos(Q1_SQ003,',01,')>0
strpos(Q1_SQ003,',02,')>0
...
strpos(Q1_SQ003,',50,')>0

This way you do not need to count. and the subquestion relevance is easier

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: gsoto
The topic has been locked.
  • gsoto
  • gsoto's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 11 months ago #198027 by gsoto
Thanks for this beautiful piece of javascript magic @Joffm – it works perfectly. With only one question for shuffling and three questions for displaying, the manual work of creating questions in the LS interface is reduced significantly. I'll be able to batch edit the relevance for each subquestion with a database query.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 11 months ago - 3 years 11 months ago #198048 by Joffm
But do not forget to add the option "None of these" to each of the three questions.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 3 years 11 months ago by Joffm.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose