0 votes
in SoSci Survey (English) by s242616 (110 points)

My survey includes several questionnaires (such as sociodemography, subjective well-being, and two main questionnaires), and I want to randomize the order of the two main questionnaires for different participants, as well as randomize the questions within each. I'm having difficulty figuring out how to do this on the site.

by SoSci Survey (328k points)
Why do you want to rotate the questions? And why the questionnaire? Known the goal is important for a helpful answer :)
by s242616 (110 points)
The two main questionnaires in our survey consists the same items, but each has different questions. The reason for randomizing the order of these two qnrs is to prevent any potential bias from answering one before the other, as this may affect the results. The other questionnaires in our survey do not need to be randomized. (or rotating?)
by SoSci Survey (328k points)
Thank you for clarifying the first rotation. What about the other one:

> as well as randomize the questions within each

And did you create the questionnaire in separate questionnaires ("compose questionnaire") within the same project or did you put all questions into one questionnaire?
by s242616 (110 points)
Yes, the items in both of the main questionnaire I mentioned need to be randomised.

I put all the parts into one questionnaire.
by SoSci Survey (328k points)
> Yes, the items in both of the main questionnaire I mentioned need to be randomised.

Please give me more details. What are the "items" you're talking about? How many questions, how many items, texts eventually? And why do you want them to rotate? I ask because question- or item-rotation may cause unwanted unexplained variance in the data, and I guess you have a good reason for the rotation. However, I need to know how many pages the questionnaires have and what questions/items, because it may interfere with the rotation of the questionnaire order.
by s242616 (110 points)
Thanks for explaining that. I believe this is a common procedure in designing questionnaires for psychology studies, as far as I know. There are approximately 95 questions (one question per page), with 70 of them related to the two main questionnaires—35 questions for each. And yes, they are all text-based. We need to rotate these two questionnaires and also randomize the items within each for participants.
by SoSci Survey (328k points)
Okay, we're getting closer, thank you. It's important to know, that we're talking about 95 separate items/questions and not about 4 questions with items, each.

> There are approximately 95 questions (one question per page)

Did you actually create 95 pages (I hope not) or did you work with loopPage()? Did you create 95 questions or one question wiht 95 items (which would be much easier to handle)? The information is important because loopPage() and setPageOrder() must not be combined.
by s242616 (110 points)
I haven't yet proceeded with creating the pages, but the 95 questions need to be shown, each on its own page. Should I create a separate page for each of them? Unfortunately, I’m not familiar with loopPage.

To summarize the structure of the survey: the first two sections contain information and the consent letter, which I have placed on separate pages. Then, participants will see a description of the two main questionnaires. Afterward, they should be directed to one of the main questionnaires (randomized for each participant) to answer 35 items, presented in a random order. Following the completion of the first main questionnaire, they will proceed to the other main questionnaire.

After the main questionnaires, they will respond to additional questions, which I can manage myself.

1 Answer

0 votes
by SoSci Survey (328k points)

Should I create a separate page for each of them? Unfortunately, I’m not familiar with loopPage.

You should make yourself familiar with that useful function. Learning it will be much faster than creating 95 pages ;)

Option A

As it definitely makes sense to work with loopPage() in your case, you should not use setPageOrder() to rotate the order of the two parts. Instead create your questionnaire with one page for the first part (using loopPage() to show it on multiple pages) and another page for the second part.

When everything works fine, make a copy of the questionnaire within your survey project, switch the two pages, and follow this manual to randomly assign the respondents to one of the two questionnaires.

Option B

You did not yet specify if you created the questions as separate questions or as items of a question. If the former is true, you can create two random generators for the rotation (see Rotate Questions), and a third one for the order. And then you can assemble a list of all 50 questions in random order. It might look like this:

$questionsA = valueList('RG01', null, 'label');
$questionsB = valueList('RG02', null, 'label');

if (value('RG03') == 1) {
    $allQuestions = array_merge($questionsA, $questionsB);
} lese {
    $allQuestions = array_merge($questionsB, $questionsA);
}

$question = loopPage($allQuestions);
question($question);
by s242616 (110 points)
I followed your instruction. However, I face warning for my code that I inserted to the page of 35 questions I mentioned. Could you please take a look at my code and see If I followed your steps correctly?

MY code:

// Step 1: Generate question IDs from b101 to b135
$questionItems = []; // Initialize an empty array
for ($i = 101; $i <= 135; $i++) {
    $questionItems[] = 'b' . $i; // Create IDs like b101, b102, ..., b135
}

// Step 2: Randomize the order of items
shuffle($questionItems); // Randomize the array

// Step 3: (Optional) Store the randomized order in the dataset
put('randomizedOrder', implode(',', $questionItems)); // Save the order for reference

// Step 4: Display the items using loopPage
loopPage($questionItems, function ($questionID) {
    question($questionID); // Display each question
}); // Properly close loopPage and its anonymous function

WARNING:
Warning: The number of opening brackets (6) does not match the number of closing brackets (5) here:
 


loopPage($questionItems, function ($questionID)

Please note that the random values created via random() or shuffle() will not automatically be stored in the data set. If necessary, you may use put() to store them.
by SoSci Survey (328k points)
> The number of opening brackets (6) does not match the number of closing brackets (5) here

You have a "function" in your code. Where does that come from? What do you intend with this?
by s242616 (110 points)
This is the code AI provided me based on the chat we had and your instruction. I'm not really familiar with php coding.
by SoSci Survey (328k points)
Well, the code does not really make sense. Please read one of the manuals which I linked in my answer to get a bit familiar with the basics. ChatGPT did not include examples from SoSci Survey when being trained, so it won't really help you.
by s242616 (110 points)
Thanks for letting me know. I familarised myself with LoopPage as you guided me, but I have problem with understanding the examples and apply them to my project. Could you help me with the code if I want to show each question of that page (from b101 to b135) in seperate pages? Is the command b101 to b135 possible? Can it be used instead of inserting each one separately into the code?
by SoSci Survey (328k points)
> Is the command b101 to b135 possible?

The FOR loop makes sense so far. You can always check the result via debug():

$questions = [];
for ($i = 101; $i <= 135; $i++) {
    $questions[] = 'b' . $i;
}
debug($questions);

If there are no other questions in B1 (is it b1 oder B1 ?) then you can have is easier:

$questions = getQuestions('b1');
debug($questions);

Yet, if you want to randomize the order, you shall use a random generator like I suggested above. Put in the question IDs there. You can easily get lines brom b101 to b135 by writing b101 into a spreadsheet in LibreOffice, and then drag the cell down. I'm not sure, if Excel can do it, as well.

The point is: When you have it in the random generator, you won't have to worry about what happens to your list when the page is loaded the next time. If you prefer to work with shuffle(), then you will need isset() and registerVariable() - more about that in the manual.
by s242616 (110 points)
According to your guidance and also the manual, I came up with this code but it doesn't work: (note: the questions are from B101 to B135)

$questions = [];
for ($i = 101; $i <= 135; $i++) {
    $questions[] = 'B' . $i;
}
debug($questions);

if (!isset($questions)) {
  // List of all questions from section B
  $questions = getQuestions('B');
  // Shuffle and cache the list of questions (array)
  shuffle($questions);
  registerVariable($questions);
}
// Process all identifiers from the $questions list
$questions = loopPage($questions);
question($questions);
by SoSci Survey (328k points)
Does debug($questions) show the proper questions?

At the moment, you create the variable $questions twice. First, with the FOR loop at the beginning, and then, again with the getQuestions('B'). You can remove the first 5 lines of your code.

Please not that getQuestions(); requires a section ID, so it must be

$questions = getQuestions('B1');

because the section is B1, not B.

And then you must not overwrite the $questions variable here:

$questions = loopPage($questions);

Please change that as follow:

$question = loopPage($questions);
question($question);

It's just important that the variable left of the equal sign is not $questions. You can use (nearly) any other word you like.

Willkommen im Online-Support von SoSci Survey.

Hier bekommen Sie schnelle und fundierte Antworten von anderen Projektleitern und direkt von SoSci Survey.

→ Eine Frage stellen


Welcome to the SoSci Survey online support.

Simply ask a question to quickly get answers from other professionals, and directly from SoSci Survey.

→ Ask a Question

...