0 votes
in SoSci Survey (English) by s224723 (130 points)
edited by SoSci Survey

Trouble with Random Generator and Page Sequence using PHP in SoSci Survey

Hello,

I am attempting to use SoSci Survey to randomize participants into two distinct groups and then direct them to different sets of questions based on their group assignment. Here's a detailed breakdown of what I'm aiming to achieve:

  1. Participants begin with the introductory page (WC).
  2. They are then randomized into one of two groups using the random generator question (RD01). The possible assignments are:
    - 1 for Group 1
    - 2 for Group 2

  3. All participants then proceed to answer common questions in the sequence: DG, MM, MD.

  4. Based on their group assignment, they should be directed to:
    - Group 1: PT page
    - Group 2: PU page

  5. After answering the group-specific questions, everyone should then move on to the common pages MC, followed by TY.

I have been employing PHP to set the page order influenced by the group assignment, but I'm encountering issues. When the PHP code is applied, the survey doesn't seem to follow the desired sequence. Moreover, when the PHP code is placed after the randomization, I receive warnings that certain pages specified in setPageOrder() don't exist, even though their IDs have been double-checked.

Here's the PHP code that's been used:

$group = value('RD01');

if ($group == 1) {
    setPageOrder(['WC', 'DG', 'MM', 'MD', 'PT', 'MC', 'TY']);
} else {
    setPageOrder(['WC', 'DG', 'MM', 'MD', 'PU', 'MC', 'TY']);
}

I've tried positioning this PHP code on different pages and adjusting its placement in relation to the randomization, but the challenges persist. I'd greatly appreciate any insights or suggestions.

Thank you in advance for your assistance.

1 Answer

0 votes
by SoSci Survey (313k points)

Based on their group assignment, they should be directed to:
- Group 1: PT page
- Group 2: PU page

The easiest solution is not to work with setPageOrder(), but to put a little filter on the page itself to show the proper questions:

$group = value('RD01');

if ($group == 1) {
  question('AB01');
  question('AB02');
  question('AB03');
} else {
  question('CB01');
  question('CB02');
  question('CB03');
}

Your PHP code looks correct, but if SoSci Survey says that it does not know the page IDs, then please make sure you have entered them as IDs, not as notes.

Also feel free to post some debug information, it makes it much easier to track the issue down.

by s224723 (130 points)
I think there is also an issue with the Random Generator as well. It started with my first page, then jumped to the supposedly randomized section, but still included all the questions for both sets of participants.

Here are the parameters I set for the Random generator (RD01):
RD01undefined Randomization: Code drawn
1 = 1
2 = 2

Here is the debugging info:
[Information]    Interview started (new case no. 88)
[Information]    Questionnaire base from project DKRefugees will be used
[Processing]    Create page 1 in questionnaire base
[Content]    Create question RD01
[Information]    The random generator RD01 drew these codes: 1
[Information]    Answer to RD02_01 = 2
[Information]    This combination has been drawn from urn "urn" and is stored to "RD02": 2
[Information]    No visible content on this page, continue with page 2
[Processing]    Create page 2 in questionnaire base
[Content]    Create question WC01
[Content]    Create question WC02
[Information]    Interview number 88 is to be continued
[Information]    Questionnaire base from project DKRefugees will be used
[Information]    Retention period on page 2 has been 27 seconds
[Processing]    Reading answers from page 1+2
[Information]    Answer to WC02 = 2
[Information]    Condition in filter WC02/1 is not met.
[Information]    100% of the questions have been answered so far
[Processing]    Create page 3 in questionnaire base
[Information]    value("RD01") = 1
[Processing]    Go to page PT (No. 6)
[Processing]    Create page 6 in questionnaire base
[Content]    Create question PT01
[Content]    Create question PT06
[Content]    Create question PT07
[Content]    Create question PT08
[Content]    Create question PT09
[Information]    Interview number 88 is to be continued
[Information]    Questionnaire base from project DKRefugees will be used
[Information]    Retention period on page 6 has been 24 seconds
[Processing]    Reading answers from page 3+6
[Information]    Answer missing for PT06_01
[Information]    Answer missing for PT07_01
[Information]    Answer missing for PT08_01
[Information]    Answer missing for PT09_01
[Information]    20% of the questions have been answered so far
[Processing]    Create page 7 in questionnaire base
[Content]    Create question PU01
[Content]    Create question PU02
[Content]    Create question PU03
[Content]    Create question PU04
[Content]    Create question PU05

Here is the code I used:
$group = value('RD01');

if ($group == 1) {
  question('PT01');
  question('PT06');
  question('PT07');
  question('PT08');
  question('PT09');
} else {
  question('PU01');
  question('PU02');
  question('PU03');
  question('PU04');
  question('PU05');
}
by SoSci Survey (313k points)
> [Information]    Answer to RD02_01 = 2
> [Information]    This combination has been drawn from urn "urn" and is stored to "RD02": 2

Seems like you use a random generator AND an urn. Remove the second one, the random generator is the further development of the urn function.

On which page is the PHP code with the setPageOrder()?
by s224723 (130 points)
Okay I have deleted the urn. I have the Random Generator first page in the survey, then I have the PHP code listed below on the page before the randomization is supposed to occur. I also just added the updated IDs and page order to the Random Generator:

1 = Wel-MDS, PT, MC,TY
2 = Wel-MDS, PU, MC,TY


Code:
question('RD01');  // Draw note from the random number generator
$pages = value('RD01', 'label');  // Read out drawn page sequence
setPageOrder($pages, 'MC');  // Apply page sequence

// The random number rolled via RD01
$number = value('RD01');
 
// Depending on the draw, one of two paths is used
if ($number == 1) {
  setPageOrder('Demo','MEIM','MDS','PT', 'MC', 'TY');
} elseif ($zahl == 2) {
  setPageOrder('Demo','MEIM','MDS','PU', 'MC', 'TY');
}
by SoSci Survey (313k points)
Okay, you have the setPageOrder() twice now. Either use the first three lines or the rest. If you use the first three lines, the content of the random generator will be used, otherwise the page order in the PHP code will be used.

On which page is the PHP code with the setPageOrder()?

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

...