break after every 50 trials and entering participant information

669 views
Skip to first unread message

anna...@gmail.com

unread,
Jul 20, 2015, 8:38:29 AM7/20/15
to jsp...@googlegroups.com
Hi,

I've just started implementing a rating task using jspsych, and I'm really happy with this library. However, I'm a bit stuck at the moment (sorry, I'm not really an experienced programer, and I haven't really worked with javascript before).

My experiment consists of videos that participants rate on a likert scale. One video is presented per page, randomly chosen from a set of videos (all of which have to be shown during the experiement. This is what I did:

var random_video = jsPsych.randomization.sample(sign_pool, sign_pool.length, false);

for(var i = 0; i < random_video.length; i++) {
var selected_video = random_video[i]

var rating_trial = {
type: 'survey-likert',
preamble: ['<video width="480" controls autoplay loop src="videos/'+selected_video+'.mov"></video>'],
questions: [[""]],
labels: [[scale_valence]],
intervals: [[7]],
data: [{video: selected_video}]
}
experiment.push(rating_trial);
};


This works great so far. However, there are 400 videos to be rated, so I would like to build in a break after every 50 rating trials. So the structure of the experiment would be 50 rating trials, break, another 50 trials, break... until all the videos have been shown. I suppose I need to use chunks to create is and while loops, but I'm not sure how to go about it.

And an unrelated query: I would like to add a little form at the beginning to add participant information (which would then be saved with their answer). Could I do this with the single stim plugin (create a form and use the entered information)? Or would it be more complicated than that?

Thank you in advance.

Best,

Anna

anna...@gmail.com

unread,
Jul 20, 2015, 5:08:36 PM7/20/15
to jsp...@googlegroups.com
Hello again,

Just to say that I solved the problem of adding in breaks between rating trials. I created a linear chunk of a rating trial and a "pause" trial and added an if/else statement which calls the chunk with the break at every n-th trial.

Here is the code:


var random_video = jsPsych.randomization.sample(video_pool, video_pool.length, false);

for(var i = 0; i < random_video.length; i++) { // looping through the randomized list of videos

var selected_video = random_video[i]

var rating_trial = { // a simple rating trial: video + rating scale
type: 'survey-likert',
preamble: ['<video width="960" controls autoplay loop src="videos/'+selected_video+'"></video>'],


questions: [[""]],
labels: [[scale_valence]],
intervals: [[7]],
data: [{video: selected_video}]
}

var rating_pause = { // Break: displays an image. Pressing any key will continue the experiment.
type: 'single-stim',
stimuli: ['img/break.jpg']
}

var trial_pause_chunk = { // chunk consisting of a rating trial and a break trial, called when the n-th video is reached
chunk_type: 'linear',
timeline: [rating_trial, rating_pause]
}

// adding in the breaks

var N_videos = 50 // number of videos after which there is a pause

if (i % N_videos == 0 && i != 0 && i != random_video.length-1) {
experiment.push(trial_pause_chunk);

} else {
experiment.push(rating_trial);
}

};

The way the if statement works means that the first break comes after n+1 videos, and every n-th video thereafter (except the final one). This is fine for me.

Best,

Anna

arnold....@gmail.com

unread,
Jul 27, 2016, 4:12:30 AM7/27/16
to jsPsych, anna...@gmail.com
For those who might still be looking for a solution, I thought I'd share how I achieved the same thing. I think that my way is much easier.

Instead of having one block with all stimuli, I created multiple blocks and each of them takes a slice of the randomised stimuli array. Then I can put a block with the break inbetween and the next block can take the next portion of the stimuli. In order to slice the trials I used the .slice function and indicated where to start and end the slice. On jsPsych 5.0.3, my code looks like this:

    var size_stimuli = [        
    { stimuli: ["one","two"], data: {exp_responce: "Q", trial_id:"0001"} },
    { stimuli: ["one","two"], data: {exp_responce: "P", trial_id:"0002"} },
     ..........
   ];

    var size_stimuli_rand = jsPsych.randomization.repeat(size_stimuli, 1);

    var block_size_1 = {
    type: 'multi-stim-multi-response',
    is_html: true,
    timeline: size_stimuli_rand.slice(0,41),
    choices: [['P','Q']],
    timing_stim: [150,2000],
    timing_response: 2000,
    }
    
  var block_pause = {
    type: "text",
    cont_key: [32],
    text: "<p><b>Break</b></p>" +
    "<p>Please take a break for a minute or two. When you are ready, you can continue with the experiment by pressing the Space bar.</p>",
    timing_post_trial: 2000
    };
    
  var block_size_2 = {
    type: 'multi-stim-multi-response',
    is_html: true,
    timeline: size_stimuli_rand.slice(41,81),
    choices: [['P','Q']], 
    timing_stim: [150,2000],
    timing_response: 2000,
    }

and so on.

secreta...@gmail.com

unread,
Feb 26, 2019, 7:24:59 PM2/26/19
to jsPsych
Hi all,

I'm a relative coding novice, trying to write an experiment that gives people a short paragraph to read, asks them to make a binary judgement and then give a confidence rating on a likert scale. I'll have 20 unique trials in the end that each will have unique options for the binary choice. I want the presentation order of each trial to be randomized across participants, and each trial to be presented only once. I have all that working in the code below!

Now my problem is that I want a break screen to appear every 5th trial. I can't figure out how to adapt the solution here (using .slice() ) to the kind of timeline set up I'm using - I adapted it from the RT Experiment Demo on the jsPsych webpage.

Any suggestions or pointers would be much appreciated! Thank you!

a truncated version of my code for reference:
------------------------------------------------------
<script>

var timeline= [];

var welcome_block = {
type: "html-keyboard-response",
stimulus: "Welcome to the experiment. Press any key to begin."
};
timeline.push(welcome_block);

// definiting two different response scales that can be used.
var scale_options = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"];

//var stimuli = "All different kinds of election watchers were asked to predict which candidate would win. Of all the pundits asked two thirds predicted that Perlmutter would win. But only one third of all predictions that Perlmutter would win were made by pundits.";

//var many_utterance = ["Many <em>pundits</em> thought Perlmutter would win.", "Many pundits thought <em>Perlmutter</em> would win."];

var stimuli = [
{ paragraph: "paragraph1",
choices: ["Many utternacereg", "many utternace rev."],
data: {cond: 'REG', para_ID: '1', correct_response: '0'}},
...
{ paragraph: "paragraph10",
choices: ["Many utternacereg", "many utternace rev."],
data: {cond: 'REG', para_ID: '10', correct_response: '0'}}, ...
];

//remember to make required TRUE after debugging finished
var trial = {
type: 'survey-multi-choice',
preamble: "<p><h3 align='left'>Instructions ... </h3></p>",
questions: [{prompt: jsPsych.timelineVariable('paragraph'), options: jsPsych.timelineVariable('choices'), horizontal: true, required: false}, {prompt: "<p><h4 align='left'>How confident are you on a scale from 1 (= not at all) to 10 (= very confident)?</h4></p>", options: scale_options, horizontal: true, required:false}],
data: jsPsych.timelineVariable('data')
};

var trial_procedure = {
timeline: [trial],
timeline_variables: stimuli,
repetitions: 1,
randomize_order:true
};
timeline.push(trial_procedure);

jsPsych.init({
timeline: timeline,
on_finish: function() {
jsPsych.data.get().localSave('csv','v6List1-part.csv');
}
});
</script>
-------------------------------------------------------

Josh de Leeuw

unread,
Mar 4, 2019, 10:02:07 PM3/4/19
to secreta...@gmail.com, jsPsych
Hi,

You could add another trial to the timeline of your trial_procedure, and make it a conditional trial that only runs if a counter is divisible by 5. You could update the counter in the on_finish event of the "trial" trial.

See here for conditional timelines: 

Cheers,
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/ab5b899f-f290-4155-9c08-3782625992ac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages