Welcome to the LimeSurvey Community Forum

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

Randomly chosen options based on quotas

  • vadindot
  • vadindot's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 7 months ago #204649 by vadindot
Randomly chosen options based on quotas was created by vadindot
I noticed this question was asked years ago, but I am not sure if this is possible in latest version(s).

I have 8 groups of questions, I want each respondent to answer 2 and I want each set of questions to be selected the same number of times. (I don't care if it isn't perfectly even, just looking for close)

And the order needs to be random

Also, I need to repeat this twice in the same survey

and I don't want to spend the money on Qualtrics
The topic has been locked.
More
3 years 7 months ago #204650 by jelo
Replied by jelo on topic Randomly chosen options based on quotas

vadindot wrote: Also, I need to repeat this twice in the same survey

Looping is not supported.
And you cannot set quotas. You can use a random number to assign respondents certain question groups. And the randomization of groups order is possible.

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 7 months ago - 3 years 7 months ago #204652 by Joffm
Replied by Joffm on topic Randomly chosen options based on quotas
Hi,
yes, randomization of groups is built in by "randomization group name".
And for 2 out of 8 you may use the "gseq" function.
Or a small javascript snippet to randomly select 2 out of 8.

But what do you mean by "twice in the same survey"?
Later again 2 out of 8? Or exactly the same 2 groups again?

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 3 years 7 months ago by Joffm.
The topic has been locked.
  • vadindot
  • vadindot's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 7 months ago #204653 by vadindot
Replied by vadindot on topic Randomly chosen options based on quotas
by twice in the same survey, I mean 2 separate batches of 8 groups, I need 2 randomly from each
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 7 months ago #204655 by Joffm
Replied by Joffm on topic Randomly chosen options based on quotas
Hi,
put a question "QSelect" of type "short text" somewhere in your first group.
Enter this script (source code mode)
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 arr1 =["A","B","C","D","E","F","G","H"];
      arr1 = shuffle(arr1);
      var arr2 =["1","2","3","4","5","6","7","8"];
      arr2 = shuffle(arr2);
      anumbers = '#' + arr1.slice(0,2).join(',')+ ',' + arr2.slice(0,2).join(',');
      $('#question{QID} input[type="text"]').val(anumbers).trigger('keyup');  
//      $('#question{QID}').hide();
   });
</script>
Let the 8 characters symbolize the first 8 (random) groups, the numbers the second.
You will get something like "#F,C,4,7"

Now give the first group of 8 groups the same "randomization group name", the second group of 8 groups a different one.
Now the relenance equation of your groups is:
1. of first 8: strpos(QSelect,"A")>0
2. of first 8: strpos(QSelect,"B")>0
3. of first 8: strpos(QSelect,"C")>0
...
1. of second 8: strpos(QSelect,"1")>0
2. of second 8: strpos(QSelect,"2")>0
...

Dont't forget to hide the question "QSelect" after testing by uncommenting this line
// $('#question{QID}').hide();


As I wrote before you can dio this without javascript unsing the "gseq" function.
As "gseq" gives you the sequentional number of displayed groups you may enter a group relevance equation like
Q1.gseq<4, where Q1 is a question in this group.

Example later.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 7 months ago #204657 by Joffm
Replied by Joffm on topic Randomly chosen options based on quotas
Here two quick examples.
I show only 2 out of 4; sufficient to show the procedure.
1st. with javascript.
You have to display "group by group"

File Attachment:

File Name: limesurvey...9716.lss
File Size:26 KB


2. With ".gseq"
You may display "group by group" or "question by question"
Remember do adapt the values in the group relevance equations.

File Attachment:

File Name: limesurvey...2388.lss
File Size:24 KB


Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose