Welcome to the LimeSurvey Community Forum

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

Randomize subquestions across survey

  • NielsFro
  • NielsFro's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
2 years 10 months ago #215791 by NielsFro
Randomize subquestions across survey was created by NielsFro
Hi all,

I'm almost sure this was asked before, but I couldn't find it...

My situation: I have a group-by-group survey with four question groups. Each group contains an array question with 10 subquestions and an open question.
For the participants, it looks like this
Survey page 1
Array with Subquestion 1, Subquestion2, ...
OpenQuestion1
Survey page 2
Array with Subquestion 11, Subquestion12, ...
OpenQuestion2
etc.

My goal: On each page, the participants shall answer an array with 10 of 40 subquestions and the open question for the page, so for example
Survey page 1
Array with Subquestion 5, Subquestion34, ...
OpenQuestion1
Survey page 2
Array with Subquestion 22, Subquestion3, ...
OpenQuestion2
Survey page 3
Array with Subquestion 9, Subquestion13, ...
OpenQuestion3
etc.

I tried:
  • Adding "rand" to the randomization group of each of the four array questions --> the order of the four arrays was shuffled
  • Setting the "Random order" to "Yes" for each of the four array questions --> the order of the subquestions within the same array was shuffled
  • Both of the above combined --> the order of the arrays and their subquestions was shuffled, but in the end it still displayed all subquestions of the respective array on the same page.
Any ideas what I could try?
Thanks a lot in advance!
Niels (Version 3.22.2+200204 )
 
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 10 months ago #215800 by holch
Replied by holch on topic Randomize subquestions across survey
There is no way (maybe some JS hack) to achieve what you are trying to achieve. Subquestions always belong to a question. You can shuffle subquestions within a question, but never within various questions.

Only solution: using questions instead of subquestions.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The following user(s) said Thank You: NielsFro
The topic has been locked.
  • NielsFro
  • NielsFro's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
2 years 10 months ago #215802 by NielsFro
Replied by NielsFro on topic Randomize subquestions across survey
Thanks for the quick reply, as always!
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 10 months ago #215803 by Joffm
Replied by Joffm on topic Randomize subquestions across survey
Hi,
you can do it like this.
4 groups: each contains your array with all subquestions (40). Display them in randomized order.

In a question of type "multiple short text" use this javascript snippet to select 4 times 10 random numbers out of the 40.
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,35,36,38,39,40];
      arr = shuffle(arr);
      var a1 = arr.slice(0, 10);
      var a2 = arr.slice(10, 20);
      var a3 = arr.slice(20, 30);
      var a4 = arr.slice(30, 40);
      alert(a4);
      $('#question{QID} input[type="text"]:eq(0)').val("#,"+a1);
      $('#question{QID} input[type="text"]:eq(1)').val("#,"+a2);
      $('#question{QID} input[type="text"]:eq(2)').val("#,"+a3);
      $('#question{QID} input[type="text"]:eq(3)').val("#,"+a4);
//    $('#question{QID}').hide();
   });
</script>
Uncomment the last line to hide this question.
You will get something like this
 

Now you display your subquestion with the subquestion relevance equation
Page 1: subquestion 1: strpos(Q0_SQ001,"01")>0
Page 1: subquestion 2: strpos(Q0_SQ001,"02")>0
Page 1: subquestion 3: strpos(Q0_SQ001,"03")>0
...
Page 2: subquestion 1: strpos(Q0_SQ002,"01")>0
Page 3: subquestion 2: strpos(Q0_SQ002,"02")>0
...
Page 4: subquestion 39: strpos(Q0_SQ004,"39")>0
Page 4: subquestion 40: strpos(Q0_SQ004,"40")>0
​​​​​​​
Joffm


 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: holch
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 10 months ago - 2 years 10 months ago #215805 by holch
Replied by holch on topic Randomize subquestions across survey
Well, there comes Joffm, proving me (at least partially) wrong.

@Joffm: Trying to make sense of what you are doing.

1. You create an array with the 40 numbers.
2. You shuffle the array
3. You split the shuffled array into 4 arrays of 10 each
4. You show only those subquestions in each array question, where the number is part of the shuffled and split array.

Correct?

Seems actually not that complicated of an approach.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

Last edit: 2 years 10 months ago by holch.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 10 months ago - 2 years 10 months ago #215808 by Joffm
Replied by Joffm on topic Randomize subquestions across survey
And here a small example.

4 pages with 3 out of 12

 

File Attachment:

File Name: limesurvey...1814.lss
File Size:56 KB


Joffm

@holch.

1. You create an array with the 40 numbers.
2. You shuffle the array
3. You split the shuffled array into 4 arrays of 10 each

This is done by the javascript.

4. You show only those subquestions in each array question, where the number is part of the shuffled and split array.

Exactly. This is the "strpos"-function.
By the way: The leading "#" ist important - not the "#", could be any other character.
Without it the first number in the string would be found at index "0". But this also means "not found". With this leading character the first index that can be found is "1".

The disadvantage is of course that each subquestion is there 4 times, either answered or not.
So you have to restructure the dataset before your analysis.


 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 2 years 10 months ago by Joffm.
The following user(s) said Thank You: holch, NielsFro
The topic has been locked.
  • NielsFro
  • NielsFro's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
2 years 10 months ago #215823 by NielsFro
Replied by NielsFro on topic Randomize subquestions across survey
Brilliant! Thanks for the idea, the code and the example - couldn't ask for more! :)
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose