- Posts: 193
- Thank you received: 69
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Group randomization with group filter
- elissa
- Topic Author
- Offline
- LimeSurvey Community Team
Less
More
3 years 5 months ago #207488
by elissa
Elzbieta Lesinska
LS voluntary Polish translator and supervisor
Group randomization with group filter was created by elissa
Hello,
I would like to ask for your help in designing the following survey:
1. Respondents are asked which products they buy, and they can choose one, two or all three products (multiple answer filter question):
Product A
Product B
Product C
2. Then everybody assesses one of the products.
I created 3 groups of questions about the products.
Group A
Group B
Group C
The problem is that a respondent can assess only the product they buy. If one buys only Product A, only the Group A should show. But if one buys two or three products one random group should show. For example, if one buys product B and C, randomly selected Group B or C should show.
This is my basic problem. I was trying relevance and group randomization as in the attached file, but this does not work. I'll be grateful if you can give me some advice.
But... and this is something extra. I'm curious if it would be possible to differentiate the probability of each Group (A, B, C) to be shown. Let's say that Product A is less popular, and it will be less often checked. However, I would like to have approximately the same number of responses for Group A, B and C. So, it would be ideal if I can "increase" the probability of Group A to be shown.
I'll be grateful for your help and be happy if I can solve even the problem of filtering the random groups.
Thank you
I would like to ask for your help in designing the following survey:
1. Respondents are asked which products they buy, and they can choose one, two or all three products (multiple answer filter question):
Product A
Product B
Product C
2. Then everybody assesses one of the products.
I created 3 groups of questions about the products.
Group A
Group B
Group C
The problem is that a respondent can assess only the product they buy. If one buys only Product A, only the Group A should show. But if one buys two or three products one random group should show. For example, if one buys product B and C, randomly selected Group B or C should show.
This is my basic problem. I was trying relevance and group randomization as in the attached file, but this does not work. I'll be grateful if you can give me some advice.
But... and this is something extra. I'm curious if it would be possible to differentiate the probability of each Group (A, B, C) to be shown. Let's say that Product A is less popular, and it will be less often checked. However, I would like to have approximately the same number of responses for Group A, B and C. So, it would be ideal if I can "increase" the probability of Group A to be shown.
I'll be grateful for your help and be happy if I can solve even the problem of filtering the random groups.
Thank you
Elzbieta Lesinska
LS voluntary Polish translator and supervisor
Attachments:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
3 years 5 months ago #207496
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Group randomization with group filter
Hi Elzbieta, I have an idea for both randomization and weighting using JavaScript. What LS version are you using?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- elissa
- Topic Author
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 193
- Thank you received: 69
3 years 5 months ago #207497
by elissa
Elzbieta Lesinska
LS voluntary Polish translator and supervisor
Replied by elissa on topic Group randomization with group filter
I use LS 3.24.3+201027
Elzbieta Lesinska
LS voluntary Polish translator and supervisor
The topic has been locked.
- Joffm
- Away
- LimeSurvey Community Team
Less
More
- Posts: 12933
- Thank you received: 3979
3 years 5 months ago - 3 years 5 months ago #207510
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Group randomization with group filter
Hi, Elissa,
as usuaul here a solution without javascript (that's Tony's area), only equations (hidden):
1. Equation (eqQ1a) : Build a string that contains the selected brands (weight by using different lengths of the strings)
{join(if(Q1_SQ001=="Y","AAAAAAA",""),if(Q1_SQ002=="Y","BBBB",""),if(Q1_SQ003=="Y","CCC",""))}
2. Equation (eqQ1b): Create a random number (1 - length of string)
{rand(1,strlen(eqQ1a))}
3. Equation (eqQ1c): Select the letter
{substr(eqQ1a,eqQ1b-1,1)}
As you show only one group you do not need group randomization.
Only relevance equations like eqQ1c=="A", eqQ1c=="B", ...
Joffm
P.S. Remove my info in QCQ1.
as usuaul here a solution without javascript (that's Tony's area), only equations (hidden):
1. Equation (eqQ1a) : Build a string that contains the selected brands (weight by using different lengths of the strings)
{join(if(Q1_SQ001=="Y","AAAAAAA",""),if(Q1_SQ002=="Y","BBBB",""),if(Q1_SQ003=="Y","CCC",""))}
2. Equation (eqQ1b): Create a random number (1 - length of string)
{rand(1,strlen(eqQ1a))}
3. Equation (eqQ1c): Select the letter
{substr(eqQ1a,eqQ1b-1,1)}
As you show only one group you do not need group randomization.
Only relevance equations like eqQ1c=="A", eqQ1c=="B", ...
Joffm
P.S. Remove my info in QCQ1.
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 3 years 5 months ago by Joffm.
The following user(s) said Thank You: elissa, tpartner
The topic has been locked.
- elissa
- Topic Author
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 193
- Thank you received: 69
3 years 5 months ago #207513
by elissa
Elzbieta Lesinska
LS voluntary Polish translator and supervisor
Replied by elissa on topic Group randomization with group filter
Hi Joffm,
I'm delighted with the elegance of the solution (and I'm happy that I can understand how it works).
Thank you very much
Elissa
I'm delighted with the elegance of the solution (and I'm happy that I can understand how it works).
Thank you very much
Elissa
Elzbieta Lesinska
LS voluntary Polish translator and supervisor
The following user(s) said Thank You: DenisChenu
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
3 years 5 months ago - 3 years 5 months ago #207521
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Group randomization with group filter
Yes, Joffm's solution is very elegant.
Mine is a little more involved but may allow more flexibility in the weightings and could be extended if you want different weighting values for different numbers of selected products.
Insert a multiple-choice question after the products multiple-choice.
We will hide this question, use JavaScript to check one item based on the weighted checked products and then use relevance to show following groups.
Insert the following script into the source of the new multiple-choice and adjust the "weights" values as necessary:
Sample survey attached:
Mine is a little more involved but may allow more flexibility in the weightings and could be extended if you want different weighting values for different numbers of selected products.
Insert a multiple-choice question after the products multiple-choice.
We will hide this question, use JavaScript to check one item based on the weighted checked products and then use relevance to show following groups.
Insert the following script into the source of the new multiple-choice and adjust the "weights" values as necessary:
Code:
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ // Define the weightings by sub-question code var weights = { 'SQ001': 50, 'SQ002': 15, 'SQ003': 35 } // Identify this question var qID = '{QID}'; var thisQuestion = $('#question'+qID); var previousQuestion = thisQuestion.prevAll('.multiple-opt:eq(0)'); var prevID = $(previousQuestion).attr('id').replace(/question/, ''); // Hide this question thisQuestion.hide(); // Listener on the checkboxes $('input:checkbox', previousQuestion).on('change', function(e) { // Reset this question $('.checkbox-item input:hidden', thisQuestion).val(''); $('.checkbox-item input:checkbox', thisQuestion).prop('checked', false).trigger('change'); // Only one item checked if($('input:checkbox:checked', previousQuestion).length == 1) { var checkedCode = $('input:checkbox:checked', previousQuestion).attr('id').split('X'+prevID)[1]; var thisItem = $('.question-item[id$="X'+qID+checkedCode+'"]'); $('input:hidden', thisItem).val('Y'); $('input:checkbox', thisItem).prop('checked', true).trigger('change'); } // Multiple items checked else if($('input:checkbox:checked', previousQuestion).length > 1) { // Build a weighted array of the checked items var sqCodesArr = []; $('input:checkbox:checked', previousQuestion).each(function(i) { var checkedCode = $(this).attr('id').split('X'+prevID)[1]; for (i = 0; i < weights[checkedCode]; i++) { sqCodesArr.push(checkedCode); } }); // Randomize the array shuffleArray(sqCodesArr); // Check the box corresponding to the first array item var checkedCode = sqCodesArr[0]; console.log(sqCodesArr); var thisItem = $('.question-item[id$="X'+qID+checkedCode+'"]'); $('input:hidden', thisItem).val('Y'); $('input:checkbox', thisItem).prop('checked', true).trigger('change'); } }); }); function shuffleArray(array) { for (var i = array.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + 1)); var temp = array[i]; array[i] = array[j]; array[j] = temp; } return array; } </script>
Sample survey attached:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 3 years 5 months ago by tpartner.
The following user(s) said Thank You: elissa
The topic has been locked.
- elissa
- Topic Author
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 193
- Thank you received: 69
3 years 5 months ago #207525
by elissa
Elzbieta Lesinska
LS voluntary Polish translator and supervisor
Replied by elissa on topic Group randomization with group filter
Hi Tony,
Looks great. Now I have much much more than I really expected.
Thank you very much.
Elissa
Looks great. Now I have much much more than I really expected.
Thank you very much.
Elissa
Elzbieta Lesinska
LS voluntary Polish translator and supervisor
The topic has been locked.