Create behavioral experiments in a browser using JavaScript
Go to file
2017-07-06 15:32:18 -04:00
css remove ambiguity #422; add btn disabled css 2017-07-06 12:58:48 -04:00
docs change default button label 2017-07-06 15:32:18 -04:00
examples remove similarity plugin #403 2017-07-06 15:32:03 -04:00
plugins change default button label 2017-07-06 15:32:18 -04:00
tests created files for different kinds of stimulus 2017-07-06 14:15:21 -04:00
.gitignore Update .gitignore 2017-01-18 12:53:17 -05:00
.travis.yml update test environment 2017-06-12 22:08:00 -04:00
contributors.md Update contributors.md 2017-07-05 11:00:09 -04:00
jspsych-logo-readme.jpg swap logo 2015-03-09 11:10:08 -04:00
jspsych.js bug fix for reset GUI 2017-07-06 15:26:46 -04:00
license.txt year updates 2016-12-15 11:43:38 -05:00
package.json update test environment 2017-06-12 22:08:00 -04:00
README.md Update README.md 2017-07-06 13:59:08 -04:00

logo

jsPsych is a JavaScript library for creating behavioral experiments that run in a web browser. jsPsych creates a framework for defining experiments and provides a set of flexible plugins that create different kinds of tasks a subject could complete during an experiment. By assembling different plugins together and customizing the parameters of each, it is possible to create many different types of experiments.

Here is a simple example of how to use the instructions plugin:











  var trial = {
    type: 'instructions',
    pages: [
      'Welcome to the experiment. Click next to begin.',
      '<div>In this experiment, you will view a ' +
      'series of images and answer questions.<br>' +
      'Answer with the keys "y" or "n".',
      'Here is an example:<br><br> ' +
      '<img src="img/age/of2.jpg"></img><br><br>' +
      'Is this person OLD or YOUNG?'
    ],
    show_clickable_nav: true
  }

  jsPsych.init({
    timeline: [trial],
  });
  
  
  
  
  
  
  
  
  

This is an example of the single-stim plugin:




 var trial_1 = {
    type: 'single-stim',
    stimulus: 'img/age/ym3.jpg',
    choices: ['E', 'I'],
    prompt:'<p>Is this person OLD or YOUNG?</p>'
  }

  var trial_2 = {
    type: 'single-stim',
    stimulus: 'img/age/of3.jpg',
    choices: ['E', 'I'],
    timing_response: 5000,
    prompt:'<p>Is this person OLD or YOUNG?</p>'
  }

  var trial_3 = {
    type: 'single-stim',
    stimulus: 'img/age/yf5.jpg',
    choices: ['E', 'I'],
    timing_response: 5000,
    prompt:'<p>Is this person OLD or YOUNG?</p>'
  }
  
  jsPsych.init({
    timeline: [trial_1, trial_2, trial_3],
    default_iti: 250
  });
  
  
  

And for a slightly longer experiment example, here is a flanker experiment which uses the text and single-stim plugins:

var test_stimuli = [
{ stimulus: "<<<<<", data: { stim_type: 'congruent'} },
{ stimulus: ">>>>>", data: { stim_type: 'congruent'} },
{ stimulus: "<<><<", data: { stim_type: 'incongruent'} },
{ stimulus: ">><>>", data: { stim_type: 'incongruent'} }
];

var test = {
timeline: [{
type: 'single-stim',
choices: [37, 39], //Left arrow, right arrow
is_html: true,
stimulus: jsPsych.timelineVariable('stimulus'),
data: jsPsych.timelineVariable('data'),
timing_response: 1500,
response_ends_trial: false
}],
timeline_variables: test_stimuli,
sample: {type: 'fixed-repetitions', size: 2}
};

var debrief = {
type: "text",
text: function() {
var congruent_rt = Math.round(jsPsych.data.get()
.filter({stim_type: 'congruent'}).select('rt').mean());
var incongruent_rt = Math.round(jsPsych.data.get()
.filter({stim_type: 'incongruent'}).select('rt').mean());
return "<p>Your average response time for congruent " + 
"trials was <strong>" + congruent_rt + "ms</strong>.</p>"+
"<p>Your average response time for incongruent trials " +
"was <strong>" + incongruent_rt + "ms</strong>.</p>";
}
};

Documentation

Documentation is available at docs.jspsych.org.

Need help?

For questions about using the library, please post to the jsPsych e-mail list. This creates a public archive of questions and solutions.

Contributing

Contributions to the code are welcome. Please use the Issue tracker system to report bugs or discuss suggestions for new features and improvements. If you would like to contribute code, submit a Pull request.

Citation

If you use this library in academic work, please cite the paper that describes jsPsych:

de Leeuw, J.R. (2015). jsPsych: A JavaScript library for creating behavioral experiments in a Web browser. Behavior Research Methods, 47(1), 1-12. doi:10.3758/s13428-014-0458-y

Response times

Wondering if jsPsych can be used for research that depends on accurate response time measurement? For most purposes, the answer is yes. Response time measurements in jsPsych (and JavaScript in general) are comparable to those taken in standard lab software like Psychophysics Toolbox and E-Prime. Response times measured in JavaScript tend to be a little bit longer (10-40ms), but have similar variance. See the following references for extensive work on this topic.

Credits

jsPsych was created by Josh de Leeuw (@jodeleeuw).

There have been many contributors to the library. Thank you!