go back to previous trial

356 views
Skip to first unread message

nazanin....@gmail.com

unread,
Feb 10, 2016, 11:42:18 AM2/10/16
to jsPsych
Hi there,

I am implementing a behavioral experiment using jspsych. The experiment is supposed to have a training phase where the participants are given the option to go back and forth between trials. The problem is I have no idea how I can make plugin.trial go back to the previous trial. I appreciate any help.

cheers,

Naz

Ian Eisenberg

unread,
Feb 10, 2016, 12:05:40 PM2/10/16
to jsPsych, nazanin....@gmail.com
Hmm. One thing you could do is maintain an array of trial parameters. Let's say the only difference between trials is the stimulus. So you'd have an array:

stims = [{stimulus: stim1},  {stimulus: stim2},  {stimulus: stim3}]

normally you would make a single-stim block like so:

block = {
type: single-stim,
timeline: stims,
...
}

which would go through each stim. Instead, you can keep track of a global variable "trial_i" and change the block to :
block = {
type single-stim,
stimulus: getStim,
...
}

where getStim = 
function() {
return stims[trial_i[.stimulus
}


Then all you need is to update the trial_i based on a button press (presumably a forward and back button). You can do this for an arbitrary number of trial variables.

Nazanin Mohammadi

unread,
Feb 10, 2016, 1:26:32 PM2/10/16
to Ian Eisenberg, jsPsych
sorry just to be clear, you are suggesting to save the stimuli as a dictionary instead of an array, is that right?

Ian Eisenberg

unread,
Feb 10, 2016, 1:29:37 PM2/10/16
to Nazanin Mohammadi, jsPsych
An array would work fine too - I just suggested a dictionary because in principle you'd want to save more parameters than just one. So your array would look more like:

[{stimulus: stim1, choices: [choice1], ...}, {stimulus: stim2, choices: [choice2[, ...}, ...]

You are basically taking the timeline object out of the stimulus and referencing a particular part of the timeline via functions indexed by trial_i.

Ian
--
Best,
Ian

Nazanin Mohammadi

unread,
Feb 10, 2016, 4:58:12 PM2/10/16
to Ian Eisenberg, jsPsych
I think I got the idea, thank you. the only thing that I can't seem to wrap my head around is how to change my plugin.create function. I thought that plugin.create function works in some sort of "batch-mode" (I am not sure if this is the right expression, all I mean is this function sets the values of parameters or stimuli for each trial right at the beginning of the experiment and then plugin.trial function takes over), whereas what you are suggesting here is some sort of "online-mode" where I can get the stimuli for each trial as we go through the experiment, is that correct or am I way off here?

Ian Eisenberg

unread,
Feb 10, 2016, 5:03:24 PM2/10/16
to Nazanin Mohammadi, jsPsych
You don't have to touch the plugin.create function. Your javascript would just look like this:

trial_i = 0
stims = [...]

getStim = function() {
 return stims[trial_i].stimulus
}

experiment_block = {
type: 'single-stim',
stimulus: getStim,
...
}

and then you just need a way to change the trial_i. This formulation doesn't actually make people go back and forth (if that's what you want). This just makes it so the *previous* trial that they go to is really just the next trial with the same parameters. The data output could look like:
[data_from_trial1,
data_from_trial2,
data_from_trial3,
data_from_trial2_again]
--
Best,
Ian

Josh de Leeuw

unread,
Feb 10, 2016, 5:05:13 PM2/10/16
to Ian Eisenberg, Nazanin Mohammadi, jsPsych
This solution takes advantage of the ability to specify functions as parameters to plugins. The functions get evaluated when the trial runs, so whatever return value they generate can take into account whatever has happened so far in the experiment.

--
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/CAH%2BqUYMtxgXQhwOK_rapeNjh7nFq7J7t89z%3DrOTFRpnyTiL%2BJA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages