Adjusting jsPsych timeline based on user feedback within plugins

373 views
Skip to first unread message

jerrysco...@gmail.com

unread,
Jul 28, 2016, 10:58:54 PM7/28/16
to jsPsych
Hi Josh,

I'm trying to put together a study using jsPsych where the participant has to learn a given set of stimuli to a criterion of 100% accuracy on a cued-recall test before advancing to the next phase of the study. So basically the program should run as follows:
(1) It presents the user with a list of sentences to memorize.
(2) It gives the user a cued-recall test of these sentences.
(3) If the user doesn't score perfectly on the test, the cycle of learning and cued-recall testing continues. If the user scores perfectly on the test, the user advances to the next phase of the study.

This has been difficult for me to implement. The first two steps have been quite straightforward by creating blocks using the single-stim and survey-text plugins. The third step, however, is quite difficult for me. As I understand, this would require that, after the program has run its blocks on the timeline to present the stimuli and give the cued-recall test, it should use an if statement to assess whether the user data from the cued-recall blocks are 100% accurate. If not, I think the program should push extra learning and cued-recall blocks into the timeline in order to create another learning-testing cycle.

Is it possible to push extra blocks (based on user input from earlier blocks) in the middle of the timeline after jsPsych has already initialized and run the first several blocks on the timeline?

Cheers,
Jerry

Josh de Leeuw

unread,
Jul 28, 2016, 11:04:53 PM7/28/16
to jerrysco...@gmail.com, jsPsych
Hi Jerry,

You can use the loop_function for a timeline to repeat the timeline. If you set randomize_order to true, then the timeline will be reordered after looping. This should get you what you are looking for.

Hope that helps,
Josh

--
You received this message because you are subscribed to the Google Groups "jsPsych" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jspsych+u...@googlegroups.com.
To post to this group, send email to jsp...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jspsych/d5d359a8-575d-4e69-b7e2-1a5965bdc308%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jerrysco...@gmail.com

unread,
Jul 28, 2016, 11:38:27 PM7/28/16
to jsPsych, jerrysco...@gmail.com
Ah, I see. I missed that in the documentation. Thank you.
Message has been deleted

jerrysco...@gmail.com

unread,
Jul 29, 2016, 7:05:49 AM7/29/16
to jsPsych, jerrysco...@gmail.com
If you have a minute, could you please help me with my code in the loop function? I know it's a little funky. I'm hoping to have the learn_cycle timeline keep looping back until the three answers from the recall_block match the three strings in the persons array.

----

var persons = ['student ', 'mailman ', 'baker '];

var recallquestion1 = ["The first person was the ________."];
var recallquestion2 = ["The second person was the ________."];
var recallquestion3 = ["The third person was the ________."];

var stimuli_trial = {
type: 'single-stim',
is_html: true,
timing_response: 500,
response_ends_present_trial: false,
timeline: [{stimulus: persons[0]},
{stimulus: persons[1]},
{stimulus: persons[2]}
]
};

var recall_block = {
type: 'survey-text',
timeline: [{questions: recallquestion1},
{questions: recallquestion2},
{questions: recallquestion3}],
randomize_order: false
};

var learn_cycle = {
timeline: [stimuli_trial, recall_block],
loop_function: function(data){
if(jobs[0] != data[0].dataAsJSON){
return true;
}
else if (jobs[1] != data[1].dataAsJSON){
return true;
}
else if (jobs[2] != data[2].dataAsJSON()){
return true;
}
else {
return false;
}
}
};

Josh de Leeuw

unread,
Jul 31, 2016, 2:36:35 PM7/31/16
to jerrysco...@gmail.com, jsPsych
the dataAsJSON method won't work on this part of the data. You can use JSON.stringify to get a JSON representation, but I don't think you need to. You probably want JSON.parse(data[0].responses)[0] to get the first response, and so on...

--
You received this message because you are subscribed to the Google Groups "jsPsych" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jspsych+u...@googlegroups.com.
To post to this group, send email to jsp...@googlegroups.com.

jerrysco...@gmail.com

unread,
Aug 3, 2016, 4:44:00 PM8/3/16
to jsPsych, jerrysco...@gmail.com
Hi Josh,

Thanks for your reply. Unfortunately I'm still unable to get it to work.

With the code following code, I keep getting this error:
Uncaught SyntaxError: Unexpected token u in JSON at position 0

var learn_cycle = {
timeline: [stimuli_trial, cued_recall_block],
loop_function: function(data){
if(persons[0] == JSON.parse(data[0].responses)[0]) {
return false;
} else {
return true;
}
}
};

I'm quite stuck on how to properly grab the responses to the survey text. Thanks.

jerrysco...@gmail.com

unread,
Aug 4, 2016, 8:55:18 PM8/4/16
to jsPsych, jerrysco...@gmail.com
The issue is resolved.

I copied a simplified version of the code below if it might be of use to anyone.
-----

<!doctype html>
<html>
<head>
<title>Simple</title>
<script src="jquery-1.11.3.js"></script>
<script src="jspsych.js"></script>
<script src="jspsych-survey-text.js"></script>
<script src="jspsych-single-stim.js"></script>
<script src="jspsych-html.js"></script>
<script src="jspsych-button-response.js"></script>
<link href="jspsych.css" rel="stylesheet" type="text/css"></link>

<style>
html {
text-align: center;
font-family: 'Open Sans', 'Arial', sans-serif;
font-size: 24px;
line-height: 1.6em;
height: 100%; }
#jspsych-survey-text-next { text-align: center; font-size: 16px; height: 50px; width: 140px; }
#jspsych-button-response-button-0 {
text-align: center;
font-size: 16px; height: 50px; width: 140px; }
#jspsych-button-response-button-1 { text-align: center; font-size: 16px; position:relative; left: 15px;
height: 50px; width: 140px; }
.jspsych-survey-text-question textarea { text-align: center; font-size: 32px; }
</style>

</head>
<body>

</body>
<script>

var timeline = [];

var persons = ['student', 'mailman', 'baker'];

var liquids = ['coffee', 'tea', 'Pepsi'];
var stimuli = [];

for(var i = 0; i < persons.length; i++) {
stimuli.push({ stimulus: 'A ' + persons[i] + ' drinks ' + liquids[i] + '.'})
}

var stimuli_block = {


type: 'single-stim',
is_html: true,
timing_response: 500,
response_ends_present_trial: false,

timeline: stimuli
};

var questions = [
['The first person was the ________.'],
['What did the first person drink?'],
['The second person was the ________.'],
['What did the second person drink?'],
['The third person was the ________.'],
['What did the third person drink?'],
];

var answers = [
persons[0],
liquids[0],
persons[1],
liquids[1],
persons[2],
liquids[2],
];

var cued_recall_block = {
type: 'survey-text',
timeline: [{questions: questions[0]},
{questions: questions[1]},
{questions: questions[2]},
{questions: questions[3]},
{questions: questions[4]},
{questions: questions[5]}],
randomize_order: false
};

var learn_cycle = {
timeline: [stimuli_block, cued_recall_block],
loop_function: function (data) {

var stimCount = persons.length;

var total = questions.length;

var correct = 0;

for (i=0; i < total; i++) {
if (answers[i].toLowerCase() == JSON.parse(data[i + stimCount].responses)['Q0'].toLowerCase()) {
correct ++;
}
}

if (correct == total) { // DLH: Need to use == for comparison
// they have answered all correctly and can exit
return false;
}
else {
// they got at least one wrong so run it again
return true;
}
}
};

timeline.push(learn_cycle);

var debrief_block = {
type: 'button-response',
choices: ['Finish'],
is_html: true,
stimulus: '<div><p style="text-align:center">DEBRIEFING</p><div><p style="text-align:left">Thank you for participating!'
};
timeline.push(debrief_block);

jsPsych.init({
timeline: timeline,
on_finish: function(data){
}
})

// hook up the Enter press on the page to click the button
$(document).on('keypress', function(e) {
if(e.which == 13) {
$('.jspsych-btn.jspsych-survey-text').trigger('click');
}
});


</script>
</html>

Reply all
Reply to author
Forward
0 new messages