Skip to main content

Decipher Support

All the topics, resources needed for Decipher.

FocusVision Knowledge Base

How to Match the Order of Questions to Answer Choices

Overview

Frequently in survey design, there is a need to route respondents to specific questions based on their answers to a prior question. Occasionally, the answer choices for this control question may be randomized. In such situations, it would be beneficial to display the question branches in the same order they were shown to respondents in the control question.

Creating the Control Question

To match the order of questions to answer choices in your survey, you must first program the control question. In the following example, the control question is a multi-select question with the brands stored in row elements:

dec_match_question_answer_order_001.png

Randomizing the Order of Answer Choices

Next, make sure that the order of your answer choices in the control question is randomized. You can accomplish this in the "Options" panel of the Survey Editor by choosing to randomize the order of your answer elements.

Using the same example, because the brand list is stored within the question rows, you would confirm that the corresponding box is checked:

dec_match_question_answer_order_002.png

This can also be done by adding shuffle="rows" to the question tag in the survey XML:

<checkbox
 label="q1"
 atleast="1"
 shuffle="rows">
 <title>Which of the following brands are you aware of?</title>
 <comment>Select all that apply</comment>
 <row label="r1">Brand A</row>
 <row label="r2">Brand B</row>
 <row label="r3">Brand C</row>
 <row label="r4">Brand D</row>
</checkbox>

Creating Question Blocks

After the control question, add a block of questions for each of the four brands. Blocks help you create structure for surveys and assign logic to a series of questions.

To add a block, select the "Block" element from the "Structural" tab of the Survey Elements menu:

dec_match_question_answer_order_003.png

In the staging area, you can include any questions located directly below the block using the “add to block” button:

dec_match_question_answer_order_004.png

Adding Logic to Blocks

This step is optional and only necessary if the follow-up questions are shown conditionally.

Add any desired logic to the question block just as you would for an individual question. For the example, assume that each block should be shown conditionally, based on whether or not respondents indicated they were aware of it in the control question.

In this case, the logic for the "Brand A" block would appear as follows:

dec_match_question_answer_order_005.png

Adding Blocks to a Parent Block

Finally, add each of the question blocks into another larger block. This larger block is known as the "parent" block and it controls the order of the subsequent blocks for each of the brands.

Blocks can be nested within one another in the same way that you would nest individual questions. To nest a block, add it above the series of brand blocks and click the “add to block” button:

dec_match_question_answer_order_006.png

In this example, the follow-up questions are nested in four individual child blocks, all within a parent block. This is unnecessary if you are only asking one question per block, but will make the process easier.

It’s important to nest page breaks within their corresponding blocks; otherwise, they will be considered separate elements.

dec_match_question_answer_order_013.png

Randomizing the Order of Questions

Then, ensure that each parent block is set to shuffle:

dec_match_question_answer_order_005.png

This can also be accomplished in the XML by adding randomizeChildren="1" to the parent block and randomize="1" to each child block. An example for the "Brand A" block is shown below:

<block label="Block1" builder:title="Parent Block" randomizeChildren="1">
 <block label="b1" cond="(q1.r1)" builder:title="A Block" randomize="1">
   <radio
   label="A1"
   randomize="0">
     <title>What is your favorite attribute of Brand A?</title>
     <comment>Select one</comment>
     <row label="r1">Attribute #1</row>
     <row label="r2">Attribute #2</row>
     <row label="r3">Attribute #3</row>
     <row label="r4">Attribute #4</row>
   </radio>
   <suspend/>
 </block>

Matching the Order of Questions to Answer Choices

With shuffling enabled, both the answer choices and follow-up questions will display in an independent, random order. To correct this, you can use the order attribute to reassign the order of the questions to match the answer choices in the control question.

Adding Page Breaks

In Decipher, page breaks, or <suspend> tags in the survey XML, are counted as elements in the order attribute. It is for this reason that you should include child blocks for each brand, even if there is only one question per brand. For example, omitting the child blocks in the example would create a situation in which there are eight elements in the block -- a mismatch for the four answer choices in the control question.

Adding an Exec Block

You can use an "Exec" element to overwrite the order. Exec elements allow users to implement raw Python code in Decipher surveys and can be added from the "Structural" tab of the Survey Elements menu:

dec_match_question_answer_order_011.png

Learn More: Exec Element

Exec blocks can also be added using the <exec> tag in the survey XML.

Overwriting the Order

The order attribute can be used within the exec block to review or modify the order in which survey elements display to respondents. The order attribute stores the randomly assigned order of the element as a Python list.

For example:

q1.rows.order = [[q1.r1], [q1.r2], [q1.r3], [q1.r4]]
Block1.order = [0,1,2,3]

The order attribute can only be used within an element once shuffling has been enabled (hence the need to randomize both the answer choices and the corresponding questions).

Modifying the Order

You can overwrite the element order by either referencing the element objects or their associated indices.

For example, to reassign the order of the parent block to match the order assigned to the rows in the control question:

#Sets the order of Block1 to match the rows of q1.
Block1.order = q1.rows.order

The order of randomized elements is determined as soon as respondents enter the survey. For that reason, the exec block and above code can be placed anywhere in the survey before the block of follow-up questions.

dec_match_question_answer_order_006.png

Learn More: Basic and Advanced Shuffling

Testing the Respondent View

You can see the respondent view for the changes by testing the survey manually:

dec_match_question_answer_order_012.png

Control Question

When you have reached the control question in your test, you should see that the order of the brands is randomized.

dec_match_question_answer_order_007.png

Question Blocks

When you reach the blocks of questions for each of the brands you selected in the control question, the order of the questions should match that of the answer choices you selected:

dec_match_question_answer_order_008.png

dec_match_question_answer_order_009.png

dec_match_question_answer_order_010.png