create randomisation within the condition | XM Community
Skip to main content
Hi, I hope this is the right section for asking this. I am using Qualtrics for a research that I have been conducting for my thesis, but I really don't know how to start. I have to create a survey where the participants are randomly directed to one of three conditions (one control, two experimental) and in each condition the participant should receive randomly two statements from two different pools (that to be honest I don't know how to create). I have already divided all the statements I need, 40 for each condition (20-20 control/20-20 experimental/20-20 experimental). How can I be sure that once the participant is assigned to one the conditions he will receive randomly and non consequentially the two statements from the two different pools?

I hope it's clear for someone what I am trying to say! 😃

Thank you in advance
Hi @Doda,

how should your questions with your statements look like? Should both statements be in one question or in two separate questions? And in the latter case should they be on one page or separate pages? And what is the type of the question?
Hi @fleb,

thank you for your reply! Basically the participant needs to receive one statement per page (4 in total) and the same three questions each time (after reading the statement). the questions are about judging the statement and the choice confidence.

Hope it's clear 😀
Hi @Doda,



You can accomplish this using the randomizer function.



You'll want to build a block for each statement, with the same 3 questions, then use the randomizer to display however many you want them to see. You can nest the randomizers to create the conditions you describe.



Good luck and holler if you need help!
Hi @Doda and @jpardicusick,

I think that creating a block for each statement is not a very elegant way since if you want to do some minor change in one of three questions, you'll have to do it forty times. Moreover, I don't see how to pick always two statements from each group and in the same time have the statements non-consequential.

I think it would be better to use JavaScript together with Loop&merge for that.



1) Select correct 4 statements for each participants and randomize their order.

Let's suppose you have randomly assigned participants to 2 groups using an embedded field called "group" which can have value either "A" or "B". (You'll have to add the third group, but that's easy).

Put following JavaScript to the question which will be shown after the respondents were divided into groups but before the statements are shown



Qualtrics.SurveyEngine.addOnload(function()

{

var pool1 = [];

var pool2 = [];



if("${e://Field/group}" == "A") //select correct pools according to the group of the participant

{

pool1 = ["a", "b", "c"]; //here will be your 20 statements

pool2 = ["aa", "bb", "cc"];

}



if("${e://Field/group}" == "B")

{

pool1 = ["d", "e", "f"];

pool2 = ["dd", "ee", "ff"];

}



function get2S(pool) {

var i0 = Math.floor(Math.random() * pool.length);

var i1 = Math.floor(Math.random() * (pool.length - 1));

i1 = i1 + (i1 >= i0 ? 1 : 0);

var selected = [pool[i0], pool[i1]];

return selected;

}

//Function to get 2 different indexes of an array

//the idea taken here: https://stackoverflow.com/questions/25424602/how-to-generate-two-different-random-numbers



function shuffle(arra1) {

var ctr = arra1.length, temp, index;

while (ctr > 0) {

index = Math.floor(Math.random() * ctr);

ctr--;

temp = arra1[ctr];

arra1[ctr] = arra1[index];

arra1[index] = temp;

}

return arra1;

}

//Shuffle the order of the array, copied from here: https://www.w3resource.com/javascript-exercises/javascript-array-exercise-17.php



var statements = get2S(pool2).concat(get2S(pool1));

statements = shuffle(statements);

Qualtrics.SurveyEngine.setEmbeddedData( "statements", statements.join() );

//Send your statements as a string to an embedded field (which must be defined in the flow); in case there are commas in your statements you will have to replace them with another separator which is not in your statements

});



2) Create a block for your statements and questions

a) Create a block and put there one descriptive text where will be your statements and your three questions which should be displayed after the statement.

b) Put following HTML element to the place where should be the statement: `<div id="s">...</div>`

c) Add Loop&merge to your block; there should be 4 loops and you don't need to fill the fields

d) Add following JavaScript to the question where will be the statement. The code will be executed in each loop.



Qualtrics.SurveyEngine.addOnload(function()

{

var statements = "${e://Field/statements}".split(","); //get your statements and split them into array

var S = statements[Number("${lm://CurrentLoopNumber}")-1]; //get the actual one using the number of the current loop

document.getElementById("s").innerHTML = S; //Put it to the HTML element



});



Check the solution carefully since I haven't. Good luck with your survey!
Sure, if you're concerned with editing the questions, you could just put the three questions in a block and then use the randomizer with a branch to present the statement and question without them being sequential. This is detailed in the page I linked earlier, in this section.



It may look something like this:

!



If your conditions are more complex, you can group items (also in that help article) and nest the randomizer.



Or you could load the questions into the library and insert them as a reference in your blocks so that if you needed to change them, you'd just change the one in the library.



@fleb Those are interesting considerations you brought up about it being editable. As far as being elegant, I honestly don't think one solution is better than another, it just depends on the OP: if they're more comfortable with code, your solution probably makes more sense as it's simpler overall. If they're not comfortable with code, mine may be less daunting for them to implement, even if more work. As you may have seen, I've often said that there may be more elegant solutions than my responses, because I am indeed not a coder but I think that one of the coolest parts of this community is that we can all offer help from our different perspectives.
thanks @fleb and @jpardicusick..My problem is the casual selection of two statement from one pool and two from the other one. For example, with pool A and pool B I don't want to obtain A1 A2 and B1 B2, basically i don't want them sequentially but casually, am I clear? the three questions are the same for each statement. thereferore, he is required to answer them 4times.

Can I obtain this with your suggestions?

Thank you in advance 😃

(I am sorry but I am really a nooby XD)
Hey @Doda,



What I would do to accomplish this is build 4 randomization flows, two for A and two for B. In the first A one, use branching logic to assign embedded data based on the answer:

!





Add an embedded data section to use math operations to add an upper and lower sequence number.

!



In the second A one, use branching logic to check that each statement is not sequential to the first one.

!



Repeat this sequence for B and you'll be all set!



Alternatively, you can request some custom code but as I mentioned before, I can't help with that one. 😀
> thanks @fleb and @jpardicusick..My problem is the casual selection of two statement from one pool and two from the other one. For example, with pool A and pool B I don't want to obtain A1 A2 and B1 B2, basically i don't want them sequentially but casually, am I clear? the three questions are the same for each statement. thereferore, he is required to answer them 4times.

> Can I obtain this with your suggestions?



My code posted above select 2 statements from each pool and then randomizes order of all 4 of them. I hope it is what you mean.

Leave a Reply