- Posts: 22
- Thank you received: 1
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Multiple choice question: split up randomly
- gsoto
- Topic Author
- Offline
- Junior Member
Less
More
3 years 11 months ago #197999
by gsoto
Multiple choice question: split up randomly was created 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:
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.
I have an approach that is based on the "randomly show x out of n questions" approach:
- In a first question group, create three randomization groups. Each randomization group contains a question (let's call it "grouping question") for every item.
- Randomly draw x questions from each group using sum(q.relevanceStatus, …) LT x
- In a second question group, create three multiple choice questions with all items
- 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.
Attachments:
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12940
- Thank you received: 3979
3 years 11 months ago - 3 years 11 months ago #198005
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Multiple choice question: split up randomly
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
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
Have a look
Joffm
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
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12940
- Thank you received: 3979
3 years 11 months ago #198008
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Multiple choice question: split up randomly
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
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
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
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 22
- Thank you received: 1
3 years 11 months ago #198027
by gsoto
Replied by gsoto on topic Multiple choice question: split up randomly
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12940
- Thank you received: 3979
3 years 11 months ago - 3 years 11 months ago #198048
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Multiple choice question: split up randomly
But do not forget to add the option "None of these" to each of the three questions.
Joffm
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.