Question randomization from random subsets | XM Community
Skip to main content

Hello, I have found posts similar to my issue, but still unsure of how to execute randomization for my survey, so was hoping for some additional help.

I have two subsets of images (Subset A has 6 images and Subset B has 6 different images). I want to present 6 images consecutively, with 3 of the 6 images being randomly selected from Subset A and the other 3 being randomly selected from Subset B. I also want these 6 total presented images to be presented in a random order, so that different survey takers would see them in different orders.

I have read recommendations for using javascript and/or embedded data in order to do this, but am still confused on how to do so. Appreciate any and all advice/feedback on how to accomplish this -thank you in advance!

 

@teresap If you’re not familiar with JavaScript or embedded data, there’s a much simpler way to do this.

  1. Create 2 blocks: Block A and Block B, each contain 6 image of it’s subset.
  2. Using Advance Randomization to insert 3 question from the list of 6 for both blocks
  3. Random the blocks order again in survey flow

This should give you 28,800 random permutation orders, which I think is enough.

Hope this helps


@Nam Nguyen thank you! I did not realize that randomizing with two blocks underneath would randomize all of the questions collectively. I appreciate your help!


Update: when I did this, it did allow me to randomize 3 questions from Block A and Block B into an overall of 6 questions, however it kept the sets together (so it would present 3 questions from Block A then 3 questions from Block B and vice versa). Is there a way for me to randomize the 6 questions, so that the sets of questions are not together?


Update: when I did this, it did allow me to randomize 3 questions from Block A and Block B into an overall of 6 questions, however it kept the sets together (so it would present 3 questions from Block A then 3 questions from Block B and vice versa). Is there a way for me to randomize the 6 questions, so that the sets of questions are not together?

@teresap There is but it will be much more complicated


@Nam Nguyen If you don’t mind explaining, I would love to try and create it despite the complications


@teresap Okay, so follow these step

  1. Make your survey flow like this,
    Declare 6 imglink that will be use to store the result → “imglink1” to “imglink6”
    1 intro block for an intro question that will contain the shuffle JavaScript
    IMG block that will present 6 image in 6 question.

     

  2. Add this JavaScript to you intro question, replace the imagelink of subset with your own.
    Qualtrics.SurveyEngine.addOnload(function() {
    // Define the image links for subset A and subset B
    var subsetA = a
    "link_to_image_A1",
    "link_to_image_A2",
    "link_to_image_A3",
    "link_to_image_A4",
    "link_to_image_A5",
    "link_to_image_A6"
    ];

    var subsetB = a
    "link_to_image_B1",
    "link_to_image_B2",
    "link_to_image_B3",
    "link_to_image_B4",
    "link_to_image_B5",
    "link_to_image_B6"
    ];

    // Function to shuffle an array
    function shuffle(array) {
    for (let i = array.length - 1; i > 0; i--) {
    const j = Math.floor(Math.random() * (i + 1));
    >array i], arrayrj]] = array[j], arrayri]];
    }
    return array;
    }

    // Shuffle both subsets
    subsetA = shuffle(subsetA);
    subsetB = shuffle(subsetB);

    // Select 3 images from each subset
    var selectedA = subsetA.slice(0, 3);
    var selectedB = subsetB.slice(0, 3);

    // Combine the selected images
    var selectedImages = selectedA.concat(selectedB);

    // Shuffle the combined selected images
    selectedImages = shuffle(selectedImages);

    // Set the images to embedded data fields
    for (var i = 0; i < selectedImages.length; i++) {
    Qualtrics.SurveyEngine.setEmbeddedData('imglink' + (i + 1), selectedImagesei]);
    }
    });

     

  3. Add the image link to your question with RichContentEditor → Source (Replace the “imglink1” from 1 to 6)
    <img style="width: 600px; height: 600px;" src="${e://Field/imglink1}">
     

     


@Nam Nguyen Thank you very much for your response. I found that the situation described in this post is very similar to mine, so I would like to ask some follow-up questions.

  1. Declare 6 imglink that will be use to store the result → “imglink1” to “imglink6”   Could you please explain this a little bit more? Is there anything that I need to do to set this up and how should this be like?
  2. Is it OK to directly use ${e://Field/imglink1} to ${e://Field/imglink6} as statements in the MCQs or Matrix questions? 

Thank you very much for your advice.


Leave a Reply