Welcome to the LimeSurvey Community Forum

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

Clustered randomization of subquestions in array

  • dandreoli
  • dandreoli's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 months 1 week ago #265262 by dandreoli
Please help us help you and fill where relevant:
Your LimeSurvey version: [see right hand bottom of your LimeSurvey admin screen]
Own server or LimeSurvey hosting:
Survey theme/template:
==================
(Write here your question/remark)==================
(Write here your question/remark)Please help us help you and fill where relevant:
Your LimeSurvey version: LimeSurvey Cloud  Version 6.5.11
Own server or LimeSurvey hosting: limesurvey hosting
Survey theme/template: fruity
==================
Hi all, 

I am working on a survey for my PhD project. In this survey, I would like to have an array based question where respondents have to indicate on a 5pt Likert scale to what extent they agree with the presented statement. To limit response bias, I would like these statements to be presented in a random order. In the set of statements I would like to include however, some subtopic or clusters can be identified. Because it does not make sense for the respondent to first think of a statement related to topic A, then one on B followed by one on A again, I would like to see the randomization based on clusters. Such that both the order of the clusters, as well as the sub-questions within a cluster are random (see the small diagram below for a representation). Does anyone know how I can go about this? I already tried to create multiple arrays, but that way the general question also gets presented on a random location because it is attached to a single array. Any help is appreciated. 

Kind regards, 
Dennis Andreoli

Example: 3 clusters: with 3 statements each:Cluster A
  •                Statement A1
  •                Statement A2
  •                Statement A3
Cluster B
  •                Statement B1
  •                Statement B2
  •                Statement B3
Cluster C
  •                Statement C1
  •                Statement C2
  •                Statement C3
 Randomization as follows:FORMULATION OF QUESTION / EXPLAINATION OF TASKCluster B
  •                Statement B3
  •                Statement B2
  •                Statement B1
Cluster A
  •                Statement A2
  •                Statement A1
  •                Statement A3
Cluster C
  •                Statement C3
  •                Statement C1
  •                Statement C2

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 months 1 week ago #265268 by Joffm
Hi,
insert this script into the question text (source code mode) (adapted from an idea of Tony Partner)
Code:
<script type="text/javascript" data-author="Tony Partner">
  $(document).on('ready pjax:scriptcomplete',function(){
 
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;
}
    
    
    //Identify this question
    var thisQuestion = $('#question{QID}');
    var thisAnswerList = $('tr.answers-list:eq(0)', thisQuestion).parent();
 
    
    // Fill the arrays with the subquestion codes
    var arrayA=[1,2,3];
    var arrayB=[4,5,6];
    var arrayC=[7,8,9];
 
    
    shuffleArray(arrayA);
    shuffleArray(arrayB);
    shuffleArray(arrayC);
    var arrayZ=[arrayA,arrayB,arrayC];
    shuffleArray(arrayZ);
    
    var answerCodes = arrayZ.join(",").split(',');
    
    // Loop through the answer codes
    $.each(answerCodes, function(i, val) {
      // Move the answer item
      $(thisAnswerList).append($('tr.answers-list[id$="X{QID}'+val+'"]', thisQuestion));
    });
  });
</script>

 

Joffm
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • dandreoli
  • dandreoli's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 months 3 weeks ago #265489 by dandreoli
Replied by dandreoli on topic Clustered randomization of subquestions in array
Hi Joffm,

Thanks a lot, it is working. Do you know of a way to 'fix' the background color alternation of the answer options by any chance?

Dennis

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 months 3 weeks ago #265494 by tpartner
See here - forums.limesurvey.org/forum/search?query...artner&childforums=1

(Scroll down to "Fix up the row background colours")

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • dandreoli
  • dandreoli's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 month 1 week ago #267883 by dandreoli
Replied by dandreoli on topic Clustered randomization of subquestions in array
Thanks! In a different question where I use the same system, I wanted to repeat the array header after each subquestion. When using the scripts provided by Joffm and yourself, the 'normal' repeat headers setting in the question settings does not work anymore.

Any way to resolve this? Thanks in advance!

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 month 1 week ago - 1 month 1 week ago #267885 by Joffm
Use your own "headers.
Code:
<script type="text/javascript" charset="utf-8">        
    $(document).ready(function() {
      // Identify this question
      var thisQuestion = $('#question{QID}');
      // Define the sub-heading text strings
      var subHeading = '<th></th><th>1</th><th>2</th><th>3</th><th>4</th><th>5</th>';
      var columnsLength = $('tr.answers-list:eq(0) > *', thisQuestion).length;
       // Insert the new rows
       $('tr.answers-list:eq(1)', thisQuestion).before('<tr class="sub-header-row">'+subHeading+'</tr>');
       $('tr.answers-list:eq(2)', thisQuestion).before('<tr class="sub-header-row">'+subHeading+'</tr>');
       $('tr.answers-list:eq(3)', thisQuestion).before('<tr class="sub-header-row">'+subHeading+'</tr>');
       // For all subquestions - or however you want
       // Fix up the row classes
      var rowClass = 1;
      $('table.subquestions-list tbody tr', thisQuestion).each(function(i) {
            if($(this).hasClass('sub-header-row')) {
                rowClass = 1
            }
            else {
                rowClass++;
            $(this).removeClass('array1 array2')
            if(rowClass % 2 == 0) {
                $(this).addClass('array2');
            }
            else {
                $(this).addClass('array1');
                }
            }
        });
    });
</script>


And some styling

Code:
<style type="text/css">
.sub-header-row {
  color: maroon;
  font-weight:bold;
  text-align: center;
  }
</style>


 

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 month 1 week ago by Joffm.

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose