0 votes
in SoSci Survey (English) by s126407 (290 points)

Dear support,

I have a multiwave survey (i.e. project) containing:
quesionnaire 1. optin (collecting e-mails of future participants)
quesionnaire 2. part 1 of experiment (they will get an e-mail with the link to this questionnaire)
quesionnaire 3. part 2 of experiment (3 days later)
quesionnaire 4. part 3 of experiment (3 days later)
quesionnaire 5. feedback (immediately after questionnaire 4)

In the part 2 of the experiment (questionnaire 3) participans are solving 6 tests which measure cognitive abilities (crystalized, fluid, and visual) and I want to give feedback to participants (5. feedback) but because of ethical restrictions i can't give feedback in terms of scores, percentiles etc. for each ability.
So, i want to give feedback which will tell participants which of these three cognitive abilities is their strength (e.g. "Crystalized/fluid/visual abilities are your strong side"). I already made internal variables which will contain mean values for each of these abilities (each is represented with 2 tasks), and let's say these internal variables are labeled "MEAN_FLUID", "MEAN_CRYSTALIZED", and "MEAN_VISUAL", and i understand that i will need a placeholder for string value (name) of each of these abilities, but first i need sosci to take these three mean scores, sort them from min to max for each participant, and present only the name of the variable containing highest value of these three variables.

Since this is a multiwave survey each participants will have data in 5 lines and since questionnaire 3 will be presented in the third line (out of 5 for each participant) i need help telling sosci to take the third line for each participant (line 3 for participant 1, line 8 for participant 2, line 13 for participant 3 etc., then take variables "MEAN_FLUID", "MEAN_CRYSTALIZED", "MEAN_VISUAL", sort them highest to lowest, determine which variable has the highest value for a specific participants, and put the name of one of these variables instead of a placeholder in feedback text (sort of like: if MEAN_FLUID highest of the three variables, placeholder = fluid; if MEAN_CRYSTALIZED highest of the three variables, placeholder=crystalized, else placeholder = MEAN_VISUAL). Can you help me with the code for this?

Thank you in advance!

Best

1 Answer

0 votes
by SoSci Survey (361k points)
selected by s126407
 
Best answer

but first i need sosci to take these three mean scores, sort them from min to max for each participant, and present only the name of the variable containing highest value of these three variables.

You can use the PHP array functions for that. Let' create an array with nice labels and the values:

$a = [
  'Fluid' => value('MEAN_FLUID'),
  'Crystalized' => value('MEAN_CRYSTALIZED'),
  'Visual' => value('MEAN_VISUAL')
];

Now, you can sort by values:

asort($a);

And finally, you get the labels in the appropriate order:

$labels = array_keys($a);
debug($labels);

need help telling sosci to take the third line for each participant

You need the panelRecords() function to retrieve data from other cases with he same SERIAL.

by s126407 (290 points)
Thanks.

I will try this. However I'm also not getting anywhere with the rest of the feedback that i intended to provide with placeholders (at least it  is not working when i try it). I suppose it is because it is a multiwave survey, and i need sosci to read values of internal variables and not use variavle names that i used in codes for registering their scores (e.g. $points11). Can you hep with this?

Thanks
by SoSci Survey (361k points)
By default, you can access the data from the current case.

If you need to access earlier data, you'll either have to store them in the database for contents (during the previous interviews) or you can use panelRecords(), see https://www.soscisurvey.de/help/doku.php/de:create:functions:panelrecords
by s126407 (290 points)
Ok, i'm not getting anywhere with panelrecords function.

Problem 1:
here are the elements:
IV06_01 - percentages of correct answers on tests of fluid abilities
IV06_02 - percentages of correct answers on tests of crystalized abilities
IV06_03 - percentages of correct answers on tests of visual abilities

feedback text elements (i gave up on placehoders):
DB06 - if crystalized is their strongest side
DB07 - if fluid is their strongest side
DB08 - if visual is their strongest side


 I tried chatgpt and this is the code it provided me with:

// load values from database
$fluid = value('IV06_01');
$crystalized = value('IV06_02');
$visual = value('IV06_03');

// make an array
$a = [
  'fluid' => $fluid,
  'crystalized' => $crystalized,
  'visual' => $visual
];

// Find the largest value
$largest = array_keys($a, max($a))[0];

// give feedback
if ($largest == 'fluid') {
    text('DB07');
}
elseif ($largest == 'crystalized') {
    text('DB06');
}
elseif ($largest == 'visual') {
    text('DB08');
}

however, it always gives the same feedback - that fluid is their strongest ability (i checked database, this was not correct, as in some trials participants' had largest score (percentage of correct answers) in crystalized or visual abilities.

Can you provide me with the correct code for this, please?


problem 2:

this is a selfrecruited participants multiwave study:
opt-in
qnr1 (mathematical tasks with scores put in database as internal variables IV03_12 and IV03_13)
qnr2 (intuitive reasoning tasks: IV03_08)
qnr2 (intuitive reasoning tasks 2: IV03_10, and feedback with placehoders)

since i didn't have success on my own chatgpt gave me this code, but the code only returns value for IV03_10 which is the value that is put to database during this current questionnaire, the same one where i provide feedback)

the code is:

// identify current respondent
$case = caseSerial();

// load IV03_08 from qnr2
$pd_qnr2 = panelData($case, array('IV03_08'), 'qnr2');

// load IV03_12 and IV03_13 from qnr1
$pd_qnr1 = panelData($case, array('IV03_12','IV03_13'), 'qnr1');

// read IV03_10 from the current questionnaire
$IV03_10 = value('IV03_10', 'text');

// safe extraction (use array_key_exists so a stored 0 is preserved)
// if the key exists we keep its value (including 0), otherwise set to empty string
if (is_array($pd_qnr2) && array_key_exists('IV03_08', $pd_qnr2)) {
    $iv03_08 = $pd_qnr2['IV03_08'];
} else {
    $iv03_08 = '';
}

if (is_array($pd_qnr1) && array_key_exists('IV03_12', $pd_qnr1)) {
    $iv03_12 = $pd_qnr1['IV03_12'];
} else {
    $iv03_12 = '';
}

if (is_array($pd_qnr1) && array_key_exists('IV03_13', $pd_qnr1)) {
    $iv03_13 = $pd_qnr1['IV03_13'];
} else {
    $iv03_13 = '';
}

// put into placeholders (these placeholders must exist in your text/html)
replace('%placeholderCRTi%', $IV03_08);   // IV03_08 from qnr2
replace('%placeholderCRTd%', $IV03_10);  // IV03_10 from current qnr - qnr3
replace('%placeholderMW1%', $IV03_12);    // IV03_12 from qnr1
replace('%placeholderMW2%', $IV03_13);    // IV03_13 from qnr1

so, when i run through all questionnaires and get to the feedback (qnr3) i get the feedback with a number of correctly solved intuitive reasoning tasks only from the current questionnaire ('%placeholderCRTd%', $iv03_10), while the rest of the placeholders appear as empty spaces, no numbers and also no plceholder (so im guessing that sosci calls up a placeholder, but it doesnt read the value assigned to it).

Can you please provide mw with the correct code for this too?

Thank you indefinitely!

Best
by SoSci Survey (361k points)
>  I tried chatgpt

You shall be aware that ChatGPT hat absolutely no idea of the context of SoSci Survey.

Unless you can understand the code it gives you (and find the errors), please do not use it. From my point of view, this here is wrong:

// Find the largest value
$largest = array_keys($a, max($a))[0];

It uses the array_keys() function completely wrong. I think, this should be array_find() instead. I personnaly would recommend (and did that in my previous answer) the asort() function.

arsort($a);
$keys = array_keys($a);
$largest = $keys[0];
by s126407 (290 points)
Thank you, I will try. Can you help me with the secind part of the feedback, it is in my comment to which you answered, but below (regarding placeholders)?

Thank you!
by SoSci Survey (361k points)
Well, again, ChatGPT hallucinated a lot but used the wrong functions and ... well ... everything else. And, please do not expect ChatGPT to read the manual, it won't.

So, you have this function panelRecords(). What does it give you in qnr2 when you created a test case via Opt-In and completed the previous questionnaires?

$data = panelRecords(['IV03_12','IV03_13'], ['QUESTNNR' => 'qnr1']);
html($data);

Tip: After the Opt-In go to the address list and check the checkbox that this is a debugging entry. Then use the mail button on the bottom of the address entry to send it the proper invitation mailings.
by s126407 (290 points)
Thank you!
Ok, i pasted this, and this is what it returns:

Array [Array [IV03_12:7]]Array [Array [IV03_13:12]]

i checked and these are correct values (7 and 12)

i also tried to call up placeholder but it doesnt give me anything (placeholders are %placeholderMW1% for value of IV03_12, and %placeholderMW1% for value of IV03_12):

[Processing]    Create page 69 in questionnaire qnr3
[Content]    Create question DB03
[Content]    Create question OI03
[Information]    The following placeholders have been prepared:
%placeholderCRTd% = (text) 8
%placeholderMW1% = (text) ???
%placeholderMW2% = (text) ???

(DB03 is text of the feedback)
(%placeholderCRTd% = (text) 8 - this is the score on the test from the current qnr)

What next?
by SoSci Survey (361k points)
> i checked and these are correct values (7 and 12)

Great, so you have all the data you need :) I understand, that you have the values in different variables, IV03_12 and IV03_13, so let's extract them from the array:

$results = [
  'IV03_12' => -1,
  'IV03_13' => -1,
];
$data = panelRecords(['IV03_12','IV03_13'], ['QUESTNNR' => 'qnr1']);
forach ($data as $record) {
  // Look for the values
  foreach (array_keys($results) as $varID) {
    if (array_key_exists($varID, $record)) {
      $results[$varID] = $record[$varID];
    }
  }
}
html($results);

Now, you have them in a plain array. What do want to do with it?
by s126407 (290 points)
I need value of IV03_12 (participants score on a test) to take place of a placeholder %placeholderMW1%

and value of IV03_13 to take place of the %placeholderMW2%
both placeholders are in the text element DB03

also, for the second part of the feedback, where you wrote to use
arsort($a);
$keys = array_keys($a);
$largest = $keys[0];

the code is the following now, but it doesnt work (it always displays the same feedback):
// load values from database
$fluid = value('IV06_01');
$crystalized = value('IV06_02');
$visual = value('IV06_03');

// make an array
$a = [
  'fluid' => $fluid,
  'crystalized' => $crystalized,
  'visual' => $visual
];

arsort($a);
$keys = array_keys($a);
$largest = $keys[0];

// give feedback
if ($largest == 'fluid') {
    text('DB07');
}
elseif ($largest == 'crystalized') {
    text('DB06');
}
elseif ($largest == 'visual') {
    text('DB08');
}

THANK YOU
by s126407 (290 points)
I tried some things, and it worked! both feedbacks Thank you!

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

...