adding documentation files

This commit is contained in:
Josh de Leeuw 2014-10-15 17:44:41 -04:00
parent b5fc742461
commit a3cd98921c
41 changed files with 2279 additions and 0 deletions

View File

@ -0,0 +1,12 @@
# About jsPsych
jsPsych was created by [Josh de Leeuw](http://pages.iu.edu/~jodeleeu) at Indiana University.
### Citation
de Leeuw, J. R. (2014). jsPsych: A JavaScript library for creating behavioral experiments in a web browser. _Behavior Research Methods_, Advance online publication. doi:10.3758/s13428-014-0458-y.
---
Documentation generated with [mkdocs](http://www.mkdocs.org)

View File

@ -0,0 +1,26 @@
# License
jsPsych is licensed under the MIT license.
>The MIT License (MIT)
>
>Copyright (c) 2014 Joshua R. de Leeuw
>
>Permission is hereby granted, free of charge, to any person obtaining a copy
>of this software and associated documentation files (the "Software"), to deal
>in the Software without restriction, including without limitation the rights
>to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
>copies of the Software, and to permit persons to whom the Software is
>furnished to do so, subject to the following conditions:
>
>The above copyright notice and this permission notice shall be included in all
>copies or substantial portions of the Software.
>
>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
>IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
>FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
>AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
>LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
>OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
>SOFTWARE.

View File

@ -0,0 +1,51 @@
# The jsPsych core library
Every jsPsych experiment utilizes the core library (contained in the `jspsych.js` file). The core library is the glue that holds all of the various plugins together. There are also several modules that are contained in the core library for tasks that are common to many different experiments. These modules are available whenever the `jspsych.js` file is loaded.
## Core library API
### Core
* jsPsych.init
* jsPsych.progress
* jsPsych.startTime
* jsPsych.totalTime
* jsPsych.preloadImages
* jsPsych.getDisplayElement
* jsPsych.finishTrial
* jsPsych.currentTrial
* jsPsych.initSettings
* jsPsych.currentChunkID
### Data module
* jsPsych.data.getData
* jsPsych.data.write
* jsPsych.data.dataAsCSV
* jsPsych.data.localSave
* jsPsych.data.getTrialsOfType
* jsPsych.data.getTrialsFromChunk
* jsPsych.data.getLastTrialData
* jsPsych.data.getLastChunkData
* jsPsych.data.displayData
### Turk module
* jsPsych.turk.turkInfo
* jsPsych.turk.submitToTurk
### Randomization module
* jsPsych.randomization.repeat
* jsPsych.randomization.factorial
### PluginAPI module
* jsPsych.pluginAPI.getKeyboardResponse
* jsPsych.pluginAPI.cancelKeyboardResponse
* jsPsych.pluginAPI.cancelAllKeyboardResponses
* jsPsych.pluginAPI.normalizeTrialVariables
* jsPsych.pluginAPI.enforceArray

View File

@ -0,0 +1,51 @@
# The jsPsych core library
Every jsPsych experiment utilizes the core library (contained in the `jspsych.js` file). The core library is the glue that holds all of the various plugins together. There are also several modules that are contained in the core library for tasks that are common to many different experiments. These modules are available whenever the `jspsych.js` file is loaded.
## Core library API
### Core
* jsPsych.init
* jsPsych.progress
* jsPsych.startTime
* jsPsych.totalTime
* jsPsych.preloadImages
* jsPsych.getDisplayElement
* jsPsych.finishTrial
* jsPsych.currentTrial
* jsPsych.initSettings
* jsPsych.currentChunkID
### Data module
* jsPsych.data.getData
* jsPsych.data.write
* jsPsych.data.dataAsCSV
* jsPsych.data.localSave
* jsPsych.data.getTrialsOfType
* jsPsych.data.getTrialsFromChunk
* jsPsych.data.getLastTrialData
* jsPsych.data.getLastChunkData
* jsPsych.data.displayData
### Turk module
* jsPsych.turk.turkInfo
* jsPsych.turk.submitToTurk
### Randomization module
* jsPsych.randomization.repeat
* jsPsych.randomization.factorial
### PluginAPI module
* jsPsych.pluginAPI.getKeyboardResponse
* jsPsych.pluginAPI.cancelKeyboardResponse
* jsPsych.pluginAPI.cancelAllKeyboardResponses
* jsPsych.pluginAPI.normalizeTrialVariables
* jsPsych.pluginAPI.enforceArray

View File

@ -0,0 +1,51 @@
# The jsPsych core library
Every jsPsych experiment utilizes the core library (contained in the `jspsych.js` file). The core library is the glue that holds all of the various plugins together. There are also several modules that are contained in the core library for tasks that are common to many different experiments. These modules are available whenever the `jspsych.js` file is loaded.
## Core library API
### Core
* jsPsych.init
* jsPsych.progress
* jsPsych.startTime
* jsPsych.totalTime
* jsPsych.preloadImages
* jsPsych.getDisplayElement
* jsPsych.finishTrial
* jsPsych.currentTrial
* jsPsych.initSettings
* jsPsych.currentChunkID
### Data module
* jsPsych.data.getData
* jsPsych.data.write
* jsPsych.data.dataAsCSV
* jsPsych.data.localSave
* jsPsych.data.getTrialsOfType
* jsPsych.data.getTrialsFromChunk
* jsPsych.data.getLastTrialData
* jsPsych.data.getLastChunkData
* jsPsych.data.displayData
### Turk module
* jsPsych.turk.turkInfo
* jsPsych.turk.submitToTurk
### Randomization module
* jsPsych.randomization.repeat
* jsPsych.randomization.factorial
### PluginAPI module
* jsPsych.pluginAPI.getKeyboardResponse
* jsPsych.pluginAPI.cancelKeyboardResponse
* jsPsych.pluginAPI.cancelAllKeyboardResponses
* jsPsych.pluginAPI.normalizeTrialVariables
* jsPsych.pluginAPI.enforceArray

View File

@ -0,0 +1,51 @@
# The jsPsych core library
Every jsPsych experiment utilizes the core library (contained in the `jspsych.js` file). The core library is the glue that holds all of the various plugins together. There are also several modules that are contained in the core library for tasks that are common to many different experiments. These modules are available whenever the `jspsych.js` file is loaded.
## Core library API
### Core
* jsPsych.init
* jsPsych.progress
* jsPsych.startTime
* jsPsych.totalTime
* jsPsych.preloadImages
* jsPsych.getDisplayElement
* jsPsych.finishTrial
* jsPsych.currentTrial
* jsPsych.initSettings
* jsPsych.currentChunkID
### Data module
* jsPsych.data.getData
* jsPsych.data.write
* jsPsych.data.dataAsCSV
* jsPsych.data.localSave
* jsPsych.data.getTrialsOfType
* jsPsych.data.getTrialsFromChunk
* jsPsych.data.getLastTrialData
* jsPsych.data.getLastChunkData
* jsPsych.data.displayData
### Turk module
* jsPsych.turk.turkInfo
* jsPsych.turk.submitToTurk
### Randomization module
* jsPsych.randomization.repeat
* jsPsych.randomization.factorial
### PluginAPI module
* jsPsych.pluginAPI.getKeyboardResponse
* jsPsych.pluginAPI.cancelKeyboardResponse
* jsPsych.pluginAPI.cancelAllKeyboardResponses
* jsPsych.pluginAPI.normalizeTrialVariables
* jsPsych.pluginAPI.enforceArray

View File

@ -0,0 +1,51 @@
# The jsPsych core library
Every jsPsych experiment utilizes the core library (contained in the `jspsych.js` file). The core library is the glue that holds all of the various plugins together. There are also several modules that are contained in the core library for tasks that are common to many different experiments. These modules are available whenever the `jspsych.js` file is loaded.
## Core library API
### Core
* jsPsych.init
* jsPsych.progress
* jsPsych.startTime
* jsPsych.totalTime
* jsPsych.preloadImages
* jsPsych.getDisplayElement
* jsPsych.finishTrial
* jsPsych.currentTrial
* jsPsych.initSettings
* jsPsych.currentChunkID
### Data module
* jsPsych.data.getData
* jsPsych.data.write
* jsPsych.data.dataAsCSV
* jsPsych.data.localSave
* jsPsych.data.getTrialsOfType
* jsPsych.data.getTrialsFromChunk
* jsPsych.data.getLastTrialData
* jsPsych.data.getLastChunkData
* jsPsych.data.displayData
### Turk module
* jsPsych.turk.turkInfo
* jsPsych.turk.submitToTurk
### Randomization module
* jsPsych.randomization.repeat
* jsPsych.randomization.factorial
### PluginAPI module
* jsPsych.pluginAPI.getKeyboardResponse
* jsPsych.pluginAPI.cancelKeyboardResponse
* jsPsych.pluginAPI.cancelAllKeyboardResponses
* jsPsych.pluginAPI.normalizeTrialVariables
* jsPsych.pluginAPI.enforceArray

View File

@ -0,0 +1,51 @@
# The jsPsych core library
Every jsPsych experiment utilizes the core library (contained in the `jspsych.js` file). The core library is the glue that holds all of the various plugins together. There are also several modules that are contained in the core library for tasks that are common to many different experiments. These modules are available whenever the `jspsych.js` file is loaded.
## Core library API
### Core
* jsPsych.init
* jsPsych.progress
* jsPsych.startTime
* jsPsych.totalTime
* jsPsych.preloadImages
* jsPsych.getDisplayElement
* jsPsych.finishTrial
* jsPsych.currentTrial
* jsPsych.initSettings
* jsPsych.currentChunkID
### Data module
* jsPsych.data.getData
* jsPsych.data.write
* jsPsych.data.dataAsCSV
* jsPsych.data.localSave
* jsPsych.data.getTrialsOfType
* jsPsych.data.getTrialsFromChunk
* jsPsych.data.getLastTrialData
* jsPsych.data.getLastChunkData
* jsPsych.data.displayData
### Turk module
* jsPsych.turk.turkInfo
* jsPsych.turk.submitToTurk
### Randomization module
* jsPsych.randomization.repeat
* jsPsych.randomization.factorial
### PluginAPI module
* jsPsych.pluginAPI.getKeyboardResponse
* jsPsych.pluginAPI.cancelKeyboardResponse
* jsPsych.pluginAPI.cancelAllKeyboardResponses
* jsPsych.pluginAPI.normalizeTrialVariables
* jsPsych.pluginAPI.enforceArray

View File

@ -0,0 +1,5 @@
h1#jspsych { text-align: center; font-size: 72px; }
td, th {
padding: 0.5em;
}

View File

@ -0,0 +1,152 @@
# Creating an Experiment: Chunks, Blocks, & Trials
To create an experiment in jsPsych, you'll need to define the experiment structure. jsPsych experiments consist of three different structures: chunks, blocks, & trials. This page goes into detail about each kind of structure, and the features related to each.
## The timeline analogy
A useful analogy for understanding chunks, blocks, & trials is a timeline. We can think of an experiment as being drawn on a timeline. The simplest version of the timeline would mark the occurrence of each **trial** in the experiment:
Sometimes, we might repeat the same kind of trial over and over again, just changing what stimulus is shown or with some other minor modification. jsPsych can group these trials together into a **block**, making it faster to define the structure of the experiment. With blocks, a timeline might look something like this:
But, what if we wanted to group trials together that weren't the same kind (i.e. didn't use the same plugin) but shared some other relationship? This is what a **chunk** does. Chunks are simply groups of blocks, but conceptually they are treated as if they are a whole separate timeline in jsPsych. This allows for more complex experiment designs, such as loops and conditional *if* statemens. With chunks, timelines can get very complicated if needed:
## Defining an experiment
The `jsPsych.init` method requires that an experiment definition is passed in as the value of the `experiment_structure` parameter.
```javascript
jsPsych.init({
experiment_structure: exp
})
```
The `exp` variable above needs to be an array, with each element of the array being either a chunk or a block.
To create a block, define a JavaScript object with a `type` property set to the particular plugin that the block uses. For example, to create a block using the `jspsych-single-stim` plugin, the corresponding object would look something like:
```javascript
var single_stim_block = {
type: 'single-stim',
stimulus: ['img/happy_face.png', 'img/sad_face.png']
}
jsPsych.init({
experiment_structure: [single_stim_block]
})
```
The above block contains two trials. The first trial will show the image file `img/happy_face.png` and the second will show `img/sad_face.png`. Different plugins have different methods for specifying multiple trials within a block. Check the documentation of the plugin that you are using for more details about how that plugin works.
To show instructions before the faces appear, define another block and add it to the `experiment_structure` array:
```javascript
var instructions_block = {
type: 'text',
text: 'Press H if the face is happy. Press S if the face is sad.'
}
var single_stim_block = {
type: 'single-stim',
stimulus: ['img/happy_face.png', 'img/sad_face.png']
}
jsPsych.init({
experiment_structure: [instructions_block, single_stim_block]
})
```
Let's imagine that we want subjects to keep viewing the faces until they get the correct response for each one. We can use a chunk to loop over the trials. To create a chunk, create an object with a `chunk_type` property set to a [valid chunk type]() and a `timeline` property containing an array of chunks and blocks within the chunk. Some chunk types will require other properties to be set as well:
```javascript
var instructions_block = {
type: 'text',
text: 'Press H if the face is happy. Press S if the face is sad.'
}
var single_stim_block = {
type: 'single-stim',
stimulus: ['img/happy_face.png', 'img/sad_face.png']
}
var looping_chunk = {
chunk_type: 'while',
timeline: [single_stim_block],
continue_function: function(data){
// code here to check if they got both answers correct.
// this is a bit too complicated for a simple tutorial
// about chunks and blocks, so imagine that the variable
// correct is true is they got both answers right, and
// false otherwise.
if(correct) { return false; }
else { return true; }
}
}
jsPsych.init({
experiment_structure: [instructions_block, looping_chunk]
})
```
## Getting formal about definitions
What **exactly** are chunks, blocks, and trials?
A **trial** defines the parameters that will be used for a single execution of a plugin's `plugin.trial` method. Since all experiments are defined in terms of plugins, this is the atomic unit of a jsPsych experiment.
A **block** is a collection of trials in which each trial uses the same plugin. Since it is very common in behavioral research to have multiple trials of the same type in a row with different stimuli, jsPsych experiments are defined at the block level by default. When creating the `experiment_structure` array for the `jsPsych.init` method, each element of the array can be either a block or a chunk.
A **chunk** is a collection of chunks or blocks that will be run in order. There are a few different kinds of chunks, which can be used to create experiments that loop or experiments that change which parts execute based on what the subject has done so far.
All three types are defined as JavaScript objects within the jsPsych code.
## Chunk types
There are different types of chunks; each defines a different way of executing the chunk's timeline. To specify the chunk type, set the `chunk_type` property of the chunk definition object.
```javascript
var chunk = {
chunk_type: 'linear',
timeline: [block1, block2]
}
```
### Linear
A linear chunk executes the timeline once and then is complete.
If the `experiment_structure` property in `jsPsych.init` contains blocks, they will be converted to linear chunks internally.
### While
A while chunk can be used for looping. It executes the timeline and then calls the `continue_function` to see if it should execute the timeline again. If the `continue_function` returns `true`, then the chunk executes again. If the function returns `false`, the chunk is complete.
The `continue_function` will be passed the data generated by the most recent execution of the chunk as the first parameter. The data will be an array; each item in the array will be the data for a single trial.
```javascript
var while_chunk = {
chunk_type: 'while',
timeline: [block1, block2],
continue_function: function(data){
// check to see if the average RT was under 1s
var sum_rt = 0;
for(var i=0; i < data.length; i++){
sum_rt += data.rt;
}
var average_rt = sum_rt / data.length;
if(average_rt < 1000){
// end the loop
return false;
} else {
// keep going until they are faster!
return true;
}
}
}
```
### If
An if chunk will only execute if some condition is met.

View File

@ -0,0 +1,190 @@
# Data Storage
There are two very different kinds of data storage: data stored in *memory* and data stored *permanently*. Data stored permanently exists even after the browser running jsPsych closes, typically in a database or in a file on a web server. Data stored in memory exists only as long the browser window running jsPsych is open.
jsPsych has many features for interacting with data stored in *memory*, but relatively few for *permanent* data storage. This is a deliberate choice, mainly because there are dozens of ways that data could be stored permanently and this strategy avoids locking in one particular solution. However, saving data permanently is obviously a crucial component of any experiment, and this page contains a few suggestions on how to accomplish permanent data storage.
## Interacting with data in memory
## Storing data permanently as a file
This is one of the simplest methods for saving jsPsych data on the server that is running the experiment. It involves a short PHP script and a few lines of JavaScript code. This method will save each participant's data as a CSV file on the server.
This method uses a simple PHP script to write files to the server:
```php
<?php
// the $_POST[] array will contain the passed in filename and data
// the directory "data" is writable by the server (chmod 777)
$filename = "data/".$_POST['filename'];
$data = $_POST['filedata'];
// write the file to disk
file_put_contents($filename, $data);
?>
```
The `file_put_contents($filename, $data)` method requires permission to write new files. An easy way to solve this is to create a directory on the server that will store the data and use the chmod command to give all users write permission (chmod 777) to that directory. In the above example, I append the directory `data/` to the filename, and that directory is writable.
To use the PHP script, the JavaScript that runs jsPsych needs to send the filename and filedata information. jQuery has an easy to use method that enables JavaScript<->PHP communication. Here's an example:
```javascript
function saveData(filename, filedata){
$.ajax({
type:'post',
cache: false,
url: 'save_data.php', // this is the path to the above PHP script
data: {filename: filename, filedata: filedata}
});
}
// call the saveData function after the experiment is over
jsPsych.init({
// code to define the experiment structure would go here...
on_finish: function(data){ saveData("filename.csv", jsPsych.data.dataAsCSV()) }
});
```
To use this in an actual experiment, it would be important to tie the filename to some unique identifier like a subject number.
## Storing data permanently in a MySQL database
The ideal solution for storing data generated by jsPsych is to write it to a database.
There are dozens of database options. MySQL is one of the most popular [relational databases](http://en.wikipedia.org/wiki/Relational_database), is free to use, and relatively easy [to install](https://www.google.com/search?q=how+to+install+mysql). This page will assume that you have a MySQL database installed on your server that is hosting the jsPsych experiment, and that your server is able to execute PHP code.
### Step 1
To communicate with a MySQL database, you will need a server-side script, such as a PHP script. The following script should work for all jsPsych data. Copy the code below into a PHP file and give it an appropriate name (e.g. savedata.php). Put the PHP file on your server in a convenient location.
```php
<?php
// Submit Data to mySQL database
// Josh de Leeuw, August 2012
// Usage:
// You need to POST the following variables to the script (e.g. using jQuery.ajax)
// "table": name of the mysql table to insert data into
// "json": json-encoded object that contains the data
// "opt_data": an associative array of additional variables to write into each row (e.g. subject ID)
//
//
//
// EDIT THE FIRST LINE OF CODE BELOW TO CONNECT TO YOUR DATABASE
//
// The script you link should contain the following two lines:
//
// $dbc = mysql_connect('localhost', 'username', 'password');
// mysql_select_db('databasename', $dbc);
//
include('database_connect.php');
// You should not need to edit below this line
function mysql_insert($table, $inserts) {
$values = array_map('mysql_real_escape_string', array_values($inserts));
$keys = array_keys($inserts);
return mysql_query('INSERT INTO `'.$table.'` (`'.implode('`,`', $keys).'`) VALUES (\''.implode('\',\'', $values).'\')');
}
// get the table name
$tab = $_POST['table'];
// decode the data object from json
$trials_obj = json_decode($_POST['json']);
// get the optional data (decode as array)
$opt_data = json_decode($_POST['opt_data'], true);
$opt_data_names = array_keys($opt_data);
// go through each element of the trials object to see if there is data
// (some plugins may not have data associated with them)
$trials = $trials_obj[0];
for($i=1; $i<count($trials_obj); $i++)
{
if(count($trials_obj[$i])>0){
// if there is data, merge that data into the $trials array
$trials = array_merge($trials, $trials_obj[$i]);
}
}
// this outputs the trials array as a string. Useful for debugging in the JavaScript console.
var_dump($trials);
// for each element in the trials array, insert the row into the mysql table
for($i=0;$i<count($trials);$i++)
{
$to_insert = (array)($trials[$i]);
// add any optional, static parameters that got passed in (like subject id or condition)
for($j=0;$j<count($opt_data_names);$j++){
$to_insert[$opt_data_names[$j]] = $opt_data[$opt_data_names[$j]];
}
$result = mysql_insert($tab, $to_insert);
}
// confirm the results
if (!$result) {
die('Invalid query: ' . mysql_error());
} else {
print "successful insert!";
}
?>
```
### Step 2
To use the above PHP script, you'll need to provide the credentials for your MySQL database. The PHP script is expecting the credentials to be stored in a separate PHP file called 'database_connect.php', located in the same directory as the PHP script. This file should look like:
```php
<?php
$dbc = mysql_connect('localhost', 'username', 'password');
mysql_select_db('databasename', $dbc);
?>
```
Replace the username and password strings with your database credentials, and replace the databasename string with the name of the database you are connecting to. For example, if my username is 'josh', my password is 'abc123', and the database is 'myresearch' then the file should look like:
```php
<?php
$dbc = mysql_connect('localhost', 'josh', 'abc123');
mysql_select_db('myresearch', $dbc);
?>
```
### Step 3
To use this PHP script, you need to invoke it from JavaScript code within your experiment page. Here's an example of how to do that.
```javascript
// data parameter should be either the value of jsPsych.data()
// or the parameter that is passed to the on_data_update callback function for the core library
// jsPsych.data() contains ALL data
// the callback function will contain only the most recently written data.
function save_data(data){
var data_table = "my_experiment_table"; // change this for different experiments
$.ajax({
type:'post',
cache: false,
url: 'path/to_php/file.php', // change this to point to your php file.
// opt_data is to add additional values to every row, like a subject ID
// replace 'key' with the column name, and 'value' with the value.
data: {
table: data_table,
json: JSON.stringify(data),
opt_data: {key: value}
},
success: function(output) { console.log(output); } // write the result to javascript console
});
}
```
Note that you'll need to change the script above to reference the table in your mysql database that will store the data, the path to the PHP file created in step 1, and change the opt_data line to include any data you want to append to the table, such as a subject ID (or remove this line entirely if you have no additional data).

View File

@ -0,0 +1,23 @@
# Using Functions as Parameters for Plugins
Most plugins allow parameters to be functions. In a typical declaration of a jsPsych block, trial parameters have to be known at the start of the experiment. This makes it impossible to alter the content of the trial based on the outcome of previous trials. When functions are used as parameters for a block of trials, the function is evaluated at the start of each trial, and the return value of the function is used as the parameter. This enables dynamic updating of the parameter based on data that a subject has generated.
Here is a sketch of how this functionality could be used to display a score to subjects that depends on their overall accuracy on the task.
```javascript
// this variable contains a score based on accuracy.
// you can update the score variable in a number of ways.
// one option would be to use the on_trial_finish callback
// function of the core library to adjust the score every
// time a trial of the appropriate kind occurs.
var score = 0;
var xab_block = {
type: 'xab',
stimuli: xab_stimuli,
prompt: function() {
return "<p>Your current score is "+score+"</p>";
}
}
```

View File

@ -0,0 +1,18 @@
# Image Preloading
If an experiment uses images as stimuli, it is important to preload the image files before running the experiment. Preloading images means that the subject's browser will download all of the image files and store them in memory on the subject's computer. This is important because loading an image file is much faster if it is already in memory on the subject's computer. Without preloading, there will be noticeable delays in the display of images, which will affect any timing measurements (such as how long the image is displayed, or a subject's response time since first viewing an image).
jsPsych has an image preloading function in the core library. For full documentation, see the [API reference page](). The function will load all of the images listed in an array, and then call a function when the loading is complete.
```javascript
// an array of paths to images that need to be loaded
var images = ['img/file1.png', 'img/file2.png', 'img/file3.png'];
jsPsych.preloadImages(images, function(){ startExperiment(); });
function startExperiment(){
jsPsych.init({
experiment_structure: exp
});
}
```

View File

@ -0,0 +1,60 @@
# Integrating with Mechanical Turk
A common use of jsPsych is to build an online experiment and find subjects using [Mechanical Turk](http://www.mturk.com/). Once an experiment is available through a web server and data is being [saved on the server](), connecting the experiment with Mechanical Turk takes only a few additional steps. jsPsych has some built-in functionality to assist with this process.
## The jsPsych.mturk module
The `jsPsych.mturk` module contains functions that are relevant for experiments running on Mechanical Turk.
## Creating an advertisement page
When potential subjects view your experiment on Mechanical Turk, they will be able to see a single webpage before deciding whether or not to accept the HIT (start the experiment). This first page is often used as an advertisement for the experiment, similar to posting a flier in a department hallway. The important thing to remember about this page is that potential subjects will be able to interact with it even if they haven't accepted the HIT. Therefore, it can be useful to change the content of the page depending on whether the HIT has been accepted or not. This is relatively easy to do using jsPsych and jQuery:
```html
<div id="experiment_link">You must accept the HIT to begin the experiment</div>.
<script>
// jsPsych has a method turkInfo() which can determine whether or not the
// HIT has been accepted.
var turkInfo = jsPsych.turkInfo();
// turkInfo.previewMode is true in two cases: when the HIT has not been
// accepted yet OR when the page is viewed outside of mechanical turk.
// The second property, outsideTurk, is true when the page is viewed
// outside of mechanical turk, so together, the statement will be true
// only when in Turk and when the HIT is not accepted yet.
if(turkInfo.previewMode && !turkInfo.outsideTurk) {
$('#turkInfo').html('<a href="link_to_experiment.html" target="_blank">Click Here to Start Experiment</a>');
}
</script>
```
One important issue with advertisement pages is that they must be served using the https protocol, which requires having an SSL certificate on the web server hosting the page. Instructions for how to do this vary depending on what kind of server you are using, so the best advice is to simply Google for instructions on how to acquire and install an SSL certificate on your particular server.
## Getting the worker ID
Every account on Mechanical Turk is given a unique identification string. Recording this ID is a useful way to keep track of who is doing your experiment. In particular, while Turk has built in tools for preventing the same person from doing a HIT more than once, there may be cases where you don't want subjects to complete related experiments. If you store the worker ID of every person who starts an experiment in a database, then you can exclude people by running a query on the database to check for the ID. jsPsych can get the workerID, assignmentID, and hitID with the turkInfo method.
```javascript
var turkInfo = jsPsych.turk.turkInfo();
// workerID
turkInfo.workerId
// hitID
turkInfo.hitId
// assignmentID
turkInfo.assignmentId
```
Recording the workerId at the start of the experiment is also a good way to track dropouts.
## Submitting results to Mechanical Turk
## Limitations
jsPsych is not designed to communicate with the Mechanical Turk API in a comprehensive manner. If you are looking for software to help you post and manage HITs, then you may want to look at [PsiTurk](http://www.psiturk.org). jsPsych and PsiTurk complement each other nicely, and there is [an example of combining the two platforms](https://psiturk.org/ee/W4v3TPAsiD6FUVY8PDyajH) on PsiTurk's experiment exchange.

View File

@ -0,0 +1,16 @@
# Automatic Progress Bar
jsPsych can show a progress bar at the top of the experiment page indicating the subject's overall completion progress. The progress bar is rendered outside the jsPsych display element, and it requires the `jspsych.css` file to be loaded on the page. As of version 4.0, the progress bar looks like this:
![Progressbar Screenshot](/img/progress_bar.png)
To show the progress bar, set the `show_progress_bar` option in `jsPsych.init` to `true`:
```javascript
jsPsych.init({
experiment_structure: exp,
show_progress_bar: true
});
```
The progress bar updates after every *top-level chunk* finishes executing. This avoids distracting updates in the middle of trials that are composed of multiple plugins, or confusing updates due to looping or conditional structures that may or may not execute depending on the actions of the subject. This also allows some flexibility for the programmer; by grouping the experiment into chunks in a deliberate manner, the timing of progress bar updates can be controlled.

View File

@ -0,0 +1,37 @@
# Randomization & Repetition
Experiments often involve presenting a set of trials in a random order. It also might be necessary to present a set of trials multiple times. jsPsych makes both of these tasks very easy to do.
## Randomizing the order of trials within a block
To randomize the order of trials within a block, add the `randomize_order` property to the block definition with a value of `true`. This option works for all plugins.
```javascript
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.png', 'img/sad_face.png'],
randomize_order: true
}
```
In the above example, there would be two trials, one with a happy face and one with a sad face, and the order of presentation would be random.
You can only specify the `randomize_order` option for blocks. It doesn't work for chunks.
The randomization operation is performed immediately before the first trial in the block executes. This means that the order of trials is impossible to know until right before the first trial begins. It also means that the order will be re-randomized if the block is started multiple times (e.g. if the block appeas in a while chunk).
## Repeating a block of trials
To repeat a block multiple times, add the `repetitions` property to the block with the value being the number of repetitions. This option works for all plugins.
```javascript
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.png', 'img/sad_face.png'],
randomize_order: true,
repetitions: 5
}
```
In the above example, there are two trials in the block. Both trials will occur (in a random order), and then the block will repeat 4 more times. The randomized order only applies to each individual repetition, so each set of two trials will contain one happy face and one sad face.

View File

@ -0,0 +1,67 @@
# jsPsych
## Overview
jsPsych is a JavaScript library for creating and running behavioral experiments in a web browser. The library provides a flexible framework for building a wide range of laboratory-like experiments that can be run online.
jsPsych prvoides the *structure* for an experiment. It handles things like determining which trial to run next, storing data, and randomizing factors/order of presentation. It also provides a set of *plugins*, which are ready-made templates for simple experimental tasks like displaying instructions or displaying a stimulus and collecting a keyboard response. A full experiment created with jsPsych will be a collection of different plugins that define the different tasks that a subject will complete.
To build an experiment with jsPsych, you'll specify the structure of the experiment using JavaScript code. You'll also need to provide the *content* that defines your experiment, such as the actual text that subjects see when they are shown instructions and the images that they will view. You can also specify a wide-range of parameters to control things like stimulus duration, which keyboard keys subjects are allowed to press, and so on.
This page gives a broad overview of how jsPsych works. More detail is available on most of the topics on this page by using the navigation above, or by following the links within the documentation.
## Loading jsPsych
To use jsPsych, you'll need to load a few JavaScript files in an HTML document. At a minimum, you'll be loading three files: the jQuery library, the main jsPsych.js library, and at least one jsPsych plugin. A bare-bones jsPsych-ready document (with the single-stim plugin loaded) will look something like the following:
```html
<!doctype html>
<html>
<head>
<script src="js/jquery.js"></script>
<script src="js/jspsych/jspsych.js"></script>
<script src="js/jspsych/plugins/jspsych-single-stim.js"></script>
</head>
<body>
</body>
</html>
```
## Creating an experiment
To use jsPsych, you'll need to create a description of your experiment in JavaScript. This description is an array; each element of the array is a **block** or a **chunk**. Chunks and blocks are special objects in jsPsych. They define sets of trials that should be grouped together (learn more about [chunks and blocks]()).
```javascript
// defining an empty array to contain the experiment description
var experiment = [];
```
Blocks are created by defining a JavaScript object with a `type` property that corresponds to a particular [plugin](). The other properties of the block object will depend on which plugin is used. Each plugin has different options.
The code below will create a block that contains two trials. The first trial will display the image file `img/happy_face.jpg` and the second trial will display the image file `img/sad_face.jpg`.
```javascript
// create a block using the 'single-stim' plugin
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.jpg','img/sad_face.jpg']
};
```
To add the block to the experiment description, we need to change the `experiment` array. There are several ways to do this in JavaScript, but we'll use the `.push()` function for generalizability.
```javascript
// add the block to the experiment description
experiment.push(block);
```
Once you have the experiment description defined, you can tell jsPsych to run the experiment by calling `jsPsych.init()` and passing your description as the value for the `experiment_structure` parameter:
```javascript
jsPsych.init({
experiment_structure: experiment
})
```
For a more in-depth tutorial about creating an experiment, take a look at the [tutorials]().

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

@ -0,0 +1,69 @@
# jsPsych
jsPsych is a JavaScript library for creating and running behavioral experiments in a web browser. The library provides a flexible framework for building a wide range of laboratory-like experiments that can be run online.
jsPsych prvoides the *structure* for an experiment. It handles things like determining which trial to run next, storing data, and randomizing factors/order of presentation. It also provides a set of *plugins*, which are ready-made templates for simple experimental tasks like displaying instructions or displaying a stimulus and collecting a keyboard response. A full experiment created with jsPsych will be a collection of different plugins that define the different tasks that a subject will complete.
To build an experiment with jsPsych, you'll specify the structure of the experiment using JavaScript code. You'll also need to provide the *content* that defines your experiment, such as the actual text that subjects see when they are shown instructions and the images that they will view. You can also specify a wide-range of parameters to control things like stimulus duration, which keyboard keys subjects are allowed to press, and so on.
This page gives a broad overview of how jsPsych works. More detail is available on most of the topics on this page by using the navigation above, or by following the links within the documentation.
## Conceptual Overview
Explaining the nested timeline approach
## Loading jsPsych
To use jsPsych, you'll need to load a few JavaScript files in an HTML document. At a minimum, you'll be loading three files: the jQuery library, the main jsPsych.js library, and at least one jsPsych plugin. A bare-bones jsPsych-ready document (with the single-stim plugin loaded) will look something like the following:
```html
<!doctype html>
<html>
<head>
<script src="js/jquery.js"></script>
<script src="js/jspsych/jspsych.js"></script>
<script src="js/jspsych/plugins/jspsych-single-stim.js"></script>
</head>
<body>
</body>
</html>
```
## Creating an experiment
To use jsPsych, you'll need to create a description of your experiment in JavaScript. This description is an array; each element of the array is a **block** or a **chunk**. Chunks and blocks are special objects in jsPsych. They define sets of trials that should be grouped together (learn more about [chunks and blocks]()).
```javascript
// defining an empty array to contain the experiment description
var experiment = [];
```
Blocks are created by defining a JavaScript object with a `type` property that corresponds to a particular [plugin](). The other properties of the block object will depend on which plugin is used. Each plugin has different options.
The code below will create a block that contains two trials. The first trial will display the image file `img/happy_face.jpg` and the second trial will display the image file `img/sad_face.jpg`.
```javascript
// create a block using the 'single-stim' plugin
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.jpg','img/sad_face.jpg']
};
```
To add the block to the experiment description, we need to change the `experiment` array. There are several ways to do this in JavaScript, but we'll use the `.push()` function for generalizability.
```javascript
// add the block to the experiment description
experiment.push(block);
```
Once you have the experiment description defined, you can tell jsPsych to run the experiment by calling `jsPsych.init()` and passing your description as the value for the `experiment_structure` parameter:
```javascript
jsPsych.init({
experiment_structure: experiment
})
```
For a more in-depth tutorial about creating an experiment, take a look at the [tutorials]().

View File

@ -0,0 +1 @@
$('table').addClass('table-striped');

View File

@ -0,0 +1,36 @@
# Plugins
In jsPsych, plugins define the kinds of tasks that subjects perform in experiments. Some plugins define very general tasks, like displaying instructions or displaying a visual stimulus and getting a keyboard response. Other plugins are more specific, displaying particular kinds of interactive stimuli, or running a specific kind of perceptual discrimination task. Creating an experiment with jsPsych involves figuring out which plugins are needed for the kinds of tasks you want to have your subjects perform.
Plugins provide a structure for a particular task. For example, the `jspsych-single-stim` plugin defines a simple structure for showing a visual stimulus and collecting a keyboard response. To use the plugin, you need to specify the content, such as what the stimulus is, what keys the subject is allowed to press, and how long the stimulus should be on the screen. Many of these content options have reasonable default values; even though the `jspsych-single-stim` plugin has over a dozen options, you only *need* to specify the stimulus in order to use it. Each plugin has its own documentation page, which describes what the plugin does and what options are available.
## Using a plugin
To use a plugin, you'll need to load the plugin's JavaScript file on your experiment page:
```html
<script src="jspsych/plugins/jspsych-single-stim.js" type="text/javascript"></script>
```
Once a plugin is loaded, you can define a block that uses that plugin. The following JavaScript code defines a trial using the `jspsych-single-stim` plugin to display an image file ('images/happy_face.jpg'). This trial uses the default values for valid keys, length of display, and so on (Learn more about creating blocks).
```javascript
var single_stim_block = {
type: 'single-stim',
stimuli: 'images/happy_face.jpg'
}
```
## List of available plugins
This table is a list of all plugins that are currently bundled with jsPsych releases. Click on the name of a plugin to view its documentation page.
Plugin | Description
------ | -----------
jspsych-animation | In jsPsych, plugins define the kinds of tasks that subjects perform in experiments. Some plugins define very general tasks, like displaying instructions or displaying a visual stimulus and getting a keyboard response.
jspsych-single-stim | In jsPsych, plugins define the kinds of tasks that subjects perform in experiments. Some plugins define very general tasks, like displaying instructions or displaying a visual stimulus and getting a keyboard response.
## Creating a plugin
There are many plugins that are bundled with jsPsych, but you aren't limited by what's currently available. Creating a

View File

@ -0,0 +1,59 @@
# jspsych-animation
This plugin displays a sequence of images at a fixed frame rate. The sequence can be looped a specified number of times. The subject is free to respond at any point during the animation, and the time of the response is recorded.
## Parameters
This table lists the parameters associated with this plugin. Parameters with a default value of *undefined* must be specified. Other parameters can be left unspecified if the default value is acceptable.
Parameter | Type | Default Value | Description
----------|------|---------------|------------
stimuli | array | *undefined* | Each element of the array is an array containing strings. The strings are paths to image files. Each array of strings specifies a single sequence, and each sequence will be its own trial. The length of this array determines the total number of trials.
frame_time | numeric | 250 | How long to display each image (in milliseconds).
frame_isi | numeric | 0 | If greater than 0, then a gap will be shown between each image in the sequence. This parameter specifies the length of the gap.
sequence_reps | numeric | 1 | How many times to show the entire sequence. There will be no gap (other than the gap specified by `frame_isi`) between repetitions.
choices | array | [ ] | This array contains the keys that the subject is allowed to press in order to respond to the stimulus. Keys can be specified as their [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) or as characters (e.g. `'a'`, `'q'`). The default value of an empty array means that all keys will be accepted as valid responses.
prompt | string | "" | This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that it can be used to provide a reminder about the action the subject is supposed to take (e.g. which key to press).
## Data Generated
In addition to the [default data collected by all plugins](), this plugin collects the following data for each trial.
Name | Type | Value
-----|------|------
animation_sequence | JSON string | An array, encoded in JSON string format. Each element of the array is an object that represents a stimulus in the animation sequence. Each object has a `stimulus` property, which is the image that was displayed, and a `time` property, which is the time in ms, measured from when the sequence began, that the stimulus was displayed.
responses | JSON string | An array, encoded in JSON format. Each element of the array is an object representing a response given by the subject. Each object has a `stimulus` property, indicating which image was displayed when the key was pressed, an `rt` property, indicating the time of the key press relative to the start of the animation, and a `key_press` property, indicating which key was pressed.
## Examples
These examples show how to define a block using the animation plugin to achieve various goals.
#### Displaying a single sequence multiple times
```javascript
// declare variable to hold animation sequence
var animation_sequence = ["img/face_1.jpg", "img/face_2.jpg", "img/face_3.jpg", "img/face_4.jpg", "img/face_3.jpg", "img/face_2.jpg"];
// create animation block for jspsych
var animation_block = {
type: 'animation',
stimuli: [animation_sequence],
repetitions: 3
};
```
#### Specifying two trials with different sequences
```javascript
// declare variables to hold animation sequences
var animation_sequence_1 = ["img/face_1.jpg", "img/face_2.jpg", "img/face_3.jpg", "img/face_4.jpg", "img/face_3.jpg", "img/face_2.jpg"];
var animation_sequence_2 = ["img/face_3.jpg", "img/face_2.jpg", "img/face_4.jpg", "img/face_1.jpg"];
// create animation block for jspsych
var animation_block = {
type: 'animation',
stimuli: [animation_sequence_1, animation_sequence_2],
repetitions: 3
};
```

View File

@ -0,0 +1,64 @@
# jspsych-single-stim plugin
This plugin displays an image or HTML-formatted content and allows the subject to respond by pressing a key on the keyboard. The stimulus can be displayed until a response is given, or for a pre-determined amount of time. The trial can be ended automatically if the subject has failed to respond within a fixed length of time.
Because this plugin can display any HTML content, it is quite versatile. It can be used for any situation in which the response generated by the subject is a single keystroke.
## Parameters
This table lists the parameters associated with this plugin. Parameters with a default value of *undefined* must be specified. Other parameters can be left unspecified if the default value is acceptable.
Parameter | Type | Default Value | Description
----------|------|---------------|------------
stimuli | array | *undefined* | Each element of the array is a stimulus. A stimulus can be either a path to an image file or a string containing valid HTML markup. Each stimulus will be presented in its own trial, and thus the length of this array determines the total number of trials.
is_html | boolean | false | If the elements of the `stimuli` array are strings containing HTML content, then this parameter must be set to true.
choices | array | [ ] | This array contains the keys that the subject is allowed to press in order to respond to the stimulus. Keys can be specified as their [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) or as characters (e.g. `'a'`, `'q'`). The default value of an empty array means that all keys will be accepted as valid responses.
prompt | string | "" | This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that it can be used to provide a reminder about the action the subject is supposed to take (e.g. which key to press).
timing_stim | numeric | -1 | How long to show the stimulus for in milliseconds. If the value is -1, then the stimulus will be shown until the subject makes a response.
timing_response | numeric | -1 | How long to wait for the subject to make a response before ending the trial in milliseconds. If the subject fails to make a response before this timer is reached, the the subject's response will be recorded as -1 for the trial and the trial will end. If the value of this parameter is -1, then the trial will wait for a response indefinitely.
continue_after_response | boolean | true | If true, then the trial will end whenever the subject makes a response (assuming they make their response before the cutoff specified by the `timing_response` parameter). If false, then the trial will continue until the value for `timing_response` is reached. You can use this parameter to force the subject to view a stimulus for a fixed amount of time, even if they respond before the time is complete.
## Data Generated
In addition to the [default data collected by all plugins](), this plugin collects the following data for each trial.
Name | Type | Value
-----|------|------
stimulus | string | Either the path to the image file or the string containing the HTML formatted content that the subject saw on this trial.
key_press | numeric | Indicates which key the subject pressed. The value is the [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) corresponding to the subject's response.
rt | numeric | The response time in milliseconds for the subject to make a response. The time is measured from when the stimulus first appears on the screen until the subject's response.
## Examples
These examples show how to define a block using the single-stim plugin to achieve various goals.
#### Displaying images until subject gives a response
```javascript
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.png', 'img/sad_face.png']
}
```
#### Restricting which keys the subject can use to respond
```javascript
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.png', 'img/sad_face.png'],
choices: ['h','s']
}
```
#### Displaying HTML content for a fixed length of time
```javascript
var block = {
type: 'single-stim',
stimuli: ['<p>Radio</p>', '<p>Towel</p>', '<p>Match</p>'],
is_html: true,
timing_response: 1500,
continue_after_response: false
}
```

View File

@ -0,0 +1,64 @@
# jspsych-single-stim plugin
This plugin displays an image or HTML-formatted content and allows the subject to respond by pressing a key on the keyboard. The stimulus can be displayed until a response is given, or for a pre-determined amount of time. The trial can be ended automatically if the subject has failed to respond within a fixed length of time.
Because this plugin can display any HTML content, it is quite versatile. It can be used for any situation in which the response generated by the subject is a single keystroke.
## Parameters
This table lists the parameters associated with this plugin. Parameters with a default value of *undefined* must be specified. Other parameters can be left unspecified if the default value is acceptable.
Parameter | Type | Default Value | Description
----------|------|---------------|------------
stimuli | array | *undefined* | Each element of the array is a stimulus. A stimulus can be either a path to an image file or a string containing valid HTML markup. Each stimulus will be presented in its own trial, and thus the length of this array determines the total number of trials.
is_html | boolean | false | If the elements of the `stimuli` array are strings containing HTML content, then this parameter must be set to true.
choices | array | [ ] | This array contains the keys that the subject is allowed to press in order to respond to the stimulus. Keys can be specified as their [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) or as characters (e.g. `'a'`, `'q'`). The default value of an empty array means that all keys will be accepted as valid responses.
prompt | string | "" | This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that it can be used to provide a reminder about the action the subject is supposed to take (e.g. which key to press).
timing_stim | numeric | -1 | How long to show the stimulus for in milliseconds. If the value is -1, then the stimulus will be shown until the subject makes a response.
timing_response | numeric | -1 | How long to wait for the subject to make a response before ending the trial in milliseconds. If the subject fails to make a response before this timer is reached, the the subject's response will be recorded as -1 for the trial and the trial will end. If the value of this parameter is -1, then the trial will wait for a response indefinitely.
continue_after_response | boolean | true | If true, then the trial will end whenever the subject makes a response (assuming they make their response before the cutoff specified by the `timing_response` parameter). If false, then the trial will continue until the value for `timing_response` is reached. You can use this parameter to force the subject to view a stimulus for a fixed amount of time, even if they respond before the time is complete.
## Data Generated
In addition to the [default data collected by all plugins](), this plugin collects the following data for each trial.
Name | Type | Value
-----|------|------
stimulus | string | Either the path to the image file or the string containing the HTML formatted content that the subject saw on this trial.
key_press | numeric | Indicates which key the subject pressed. The value is the [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) corresponding to the subject's response.
rt | numeric | The response time in milliseconds for the subject to make a response. The time is measured from when the stimulus first appears on the screen until the subject's response.
## Examples
These examples show how to define a block using the single-stim plugin to achieve various goals.
#### Displaying images until subject gives a response
```javascript
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.png', 'img/sad_face.png']
}
```
#### Restricting which keys the subject can use to respond
```javascript
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.png', 'img/sad_face.png'],
choices: ['h','s']
}
```
#### Displaying HTML content for a fixed length of time
```javascript
var block = {
type: 'single-stim',
stimuli: ['<p>Radio</p>', '<p>Towel</p>', '<p>Match</p>'],
is_html: true,
timing_response: 1500,
continue_after_response: false
}
```

View File

@ -0,0 +1,64 @@
# jspsych-single-stim plugin
This plugin displays an image or HTML-formatted content and allows the subject to respond by pressing a key on the keyboard. The stimulus can be displayed until a response is given, or for a pre-determined amount of time. The trial can be ended automatically if the subject has failed to respond within a fixed length of time.
Because this plugin can display any HTML content, it is quite versatile. It can be used for any situation in which the response generated by the subject is a single keystroke.
## Parameters
This table lists the parameters associated with this plugin. Parameters with a default value of *undefined* must be specified. Other parameters can be left unspecified if the default value is acceptable.
Parameter | Type | Default Value | Description
----------|------|---------------|------------
stimuli | array | *undefined* | Each element of the array is a stimulus. A stimulus can be either a path to an image file or a string containing valid HTML markup. Each stimulus will be presented in its own trial, and thus the length of this array determines the total number of trials.
is_html | boolean | false | If the elements of the `stimuli` array are strings containing HTML content, then this parameter must be set to true.
choices | array | [ ] | This array contains the keys that the subject is allowed to press in order to respond to the stimulus. Keys can be specified as their [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) or as characters (e.g. `'a'`, `'q'`). The default value of an empty array means that all keys will be accepted as valid responses.
prompt | string | "" | This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that it can be used to provide a reminder about the action the subject is supposed to take (e.g. which key to press).
timing_stim | numeric | -1 | How long to show the stimulus for in milliseconds. If the value is -1, then the stimulus will be shown until the subject makes a response.
timing_response | numeric | -1 | How long to wait for the subject to make a response before ending the trial in milliseconds. If the subject fails to make a response before this timer is reached, the the subject's response will be recorded as -1 for the trial and the trial will end. If the value of this parameter is -1, then the trial will wait for a response indefinitely.
continue_after_response | boolean | true | If true, then the trial will end whenever the subject makes a response (assuming they make their response before the cutoff specified by the `timing_response` parameter). If false, then the trial will continue until the value for `timing_response` is reached. You can use this parameter to force the subject to view a stimulus for a fixed amount of time, even if they respond before the time is complete.
## Data Generated
In addition to the [default data collected by all plugins](), this plugin collects the following data for each trial.
Name | Type | Value
-----|------|------
stimulus | string | Either the path to the image file or the string containing the HTML formatted content that the subject saw on this trial.
key_press | numeric | Indicates which key the subject pressed. The value is the [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) corresponding to the subject's response.
rt | numeric | The response time in milliseconds for the subject to make a response. The time is measured from when the stimulus first appears on the screen until the subject's response.
## Examples
These examples show how to define a block using the single-stim plugin to achieve various goals.
#### Displaying images until subject gives a response
```javascript
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.png', 'img/sad_face.png']
}
```
#### Restricting which keys the subject can use to respond
```javascript
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.png', 'img/sad_face.png'],
choices: ['h','s']
}
```
#### Displaying HTML content for a fixed length of time
```javascript
var block = {
type: 'single-stim',
stimuli: ['<p>Radio</p>', '<p>Towel</p>', '<p>Match</p>'],
is_html: true,
timing_response: 1500,
continue_after_response: false
}
```

View File

@ -0,0 +1,64 @@
# jspsych-single-stim plugin
This plugin displays an image or HTML-formatted content and allows the subject to respond by pressing a key on the keyboard. The stimulus can be displayed until a response is given, or for a pre-determined amount of time. The trial can be ended automatically if the subject has failed to respond within a fixed length of time.
Because this plugin can display any HTML content, it is quite versatile. It can be used for any situation in which the response generated by the subject is a single keystroke.
## Parameters
This table lists the parameters associated with this plugin. Parameters with a default value of *undefined* must be specified. Other parameters can be left unspecified if the default value is acceptable.
Parameter | Type | Default Value | Description
----------|------|---------------|------------
stimuli | array | *undefined* | Each element of the array is a stimulus. A stimulus can be either a path to an image file or a string containing valid HTML markup. Each stimulus will be presented in its own trial, and thus the length of this array determines the total number of trials.
is_html | boolean | false | If the elements of the `stimuli` array are strings containing HTML content, then this parameter must be set to true.
choices | array | [ ] | This array contains the keys that the subject is allowed to press in order to respond to the stimulus. Keys can be specified as their [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) or as characters (e.g. `'a'`, `'q'`). The default value of an empty array means that all keys will be accepted as valid responses.
prompt | string | "" | This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that it can be used to provide a reminder about the action the subject is supposed to take (e.g. which key to press).
timing_stim | numeric | -1 | How long to show the stimulus for in milliseconds. If the value is -1, then the stimulus will be shown until the subject makes a response.
timing_response | numeric | -1 | How long to wait for the subject to make a response before ending the trial in milliseconds. If the subject fails to make a response before this timer is reached, the the subject's response will be recorded as -1 for the trial and the trial will end. If the value of this parameter is -1, then the trial will wait for a response indefinitely.
continue_after_response | boolean | true | If true, then the trial will end whenever the subject makes a response (assuming they make their response before the cutoff specified by the `timing_response` parameter). If false, then the trial will continue until the value for `timing_response` is reached. You can use this parameter to force the subject to view a stimulus for a fixed amount of time, even if they respond before the time is complete.
## Data Generated
In addition to the [default data collected by all plugins](), this plugin collects the following data for each trial.
Name | Type | Value
-----|------|------
stimulus | string | Either the path to the image file or the string containing the HTML formatted content that the subject saw on this trial.
key_press | numeric | Indicates which key the subject pressed. The value is the [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) corresponding to the subject's response.
rt | numeric | The response time in milliseconds for the subject to make a response. The time is measured from when the stimulus first appears on the screen until the subject's response.
## Examples
These examples show how to define a block using the single-stim plugin to achieve various goals.
#### Displaying images until subject gives a response
```javascript
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.png', 'img/sad_face.png']
}
```
#### Restricting which keys the subject can use to respond
```javascript
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.png', 'img/sad_face.png'],
choices: ['h','s']
}
```
#### Displaying HTML content for a fixed length of time
```javascript
var block = {
type: 'single-stim',
stimuli: ['<p>Radio</p>', '<p>Towel</p>', '<p>Match</p>'],
is_html: true,
timing_response: 1500,
continue_after_response: false
}
```

View File

@ -0,0 +1,64 @@
# jspsych-single-stim plugin
This plugin displays an image or HTML-formatted content and allows the subject to respond by pressing a key on the keyboard. The stimulus can be displayed until a response is given, or for a pre-determined amount of time. The trial can be ended automatically if the subject has failed to respond within a fixed length of time.
Because this plugin can display any HTML content, it is quite versatile. It can be used for any situation in which the response generated by the subject is a single keystroke.
## Parameters
This table lists the parameters associated with this plugin. Parameters with a default value of *undefined* must be specified. Other parameters can be left unspecified if the default value is acceptable.
Parameter | Type | Default Value | Description
----------|------|---------------|------------
stimuli | array | *undefined* | Each element of the array is a stimulus. A stimulus can be either a path to an image file or a string containing valid HTML markup. Each stimulus will be presented in its own trial, and thus the length of this array determines the total number of trials.
is_html | boolean | false | If the elements of the `stimuli` array are strings containing HTML content, then this parameter must be set to true.
choices | array | [ ] | This array contains the keys that the subject is allowed to press in order to respond to the stimulus. Keys can be specified as their [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) or as characters (e.g. `'a'`, `'q'`). The default value of an empty array means that all keys will be accepted as valid responses.
prompt | string | "" | This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that it can be used to provide a reminder about the action the subject is supposed to take (e.g. which key to press).
timing_stim | numeric | -1 | How long to show the stimulus for in milliseconds. If the value is -1, then the stimulus will be shown until the subject makes a response.
timing_response | numeric | -1 | How long to wait for the subject to make a response before ending the trial in milliseconds. If the subject fails to make a response before this timer is reached, the the subject's response will be recorded as -1 for the trial and the trial will end. If the value of this parameter is -1, then the trial will wait for a response indefinitely.
continue_after_response | boolean | true | If true, then the trial will end whenever the subject makes a response (assuming they make their response before the cutoff specified by the `timing_response` parameter). If false, then the trial will continue until the value for `timing_response` is reached. You can use this parameter to force the subject to view a stimulus for a fixed amount of time, even if they respond before the time is complete.
## Data Generated
In addition to the [default data collected by all plugins](), this plugin collects the following data for each trial.
Name | Type | Value
-----|------|------
stimulus | string | Either the path to the image file or the string containing the HTML formatted content that the subject saw on this trial.
key_press | numeric | Indicates which key the subject pressed. The value is the [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) corresponding to the subject's response.
rt | numeric | The response time in milliseconds for the subject to make a response. The time is measured from when the stimulus first appears on the screen until the subject's response.
## Examples
These examples show how to define a block using the single-stim plugin to achieve various goals.
#### Displaying images until subject gives a response
```javascript
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.png', 'img/sad_face.png']
}
```
#### Restricting which keys the subject can use to respond
```javascript
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.png', 'img/sad_face.png'],
choices: ['h','s']
}
```
#### Displaying HTML content for a fixed length of time
```javascript
var block = {
type: 'single-stim',
stimuli: ['<p>Radio</p>', '<p>Towel</p>', '<p>Match</p>'],
is_html: true,
timing_response: 1500,
continue_after_response: false
}
```

View File

@ -0,0 +1,64 @@
# jspsych-single-stim plugin
This plugin displays an image or HTML-formatted content and allows the subject to respond by pressing a key on the keyboard. The stimulus can be displayed until a response is given, or for a pre-determined amount of time. The trial can be ended automatically if the subject has failed to respond within a fixed length of time.
Because this plugin can display any HTML content, it is quite versatile. It can be used for any situation in which the response generated by the subject is a single keystroke.
## Parameters
This table lists the parameters associated with this plugin. Parameters with a default value of *undefined* must be specified. Other parameters can be left unspecified if the default value is acceptable.
Parameter | Type | Default Value | Description
----------|------|---------------|------------
stimuli | array | *undefined* | Each element of the array is a stimulus. A stimulus can be either a path to an image file or a string containing valid HTML markup. Each stimulus will be presented in its own trial, and thus the length of this array determines the total number of trials.
is_html | boolean | false | If the elements of the `stimuli` array are strings containing HTML content, then this parameter must be set to true.
choices | array | [ ] | This array contains the keys that the subject is allowed to press in order to respond to the stimulus. Keys can be specified as their [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) or as characters (e.g. `'a'`, `'q'`). The default value of an empty array means that all keys will be accepted as valid responses.
prompt | string | "" | This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that it can be used to provide a reminder about the action the subject is supposed to take (e.g. which key to press).
timing_stim | numeric | -1 | How long to show the stimulus for in milliseconds. If the value is -1, then the stimulus will be shown until the subject makes a response.
timing_response | numeric | -1 | How long to wait for the subject to make a response before ending the trial in milliseconds. If the subject fails to make a response before this timer is reached, the the subject's response will be recorded as -1 for the trial and the trial will end. If the value of this parameter is -1, then the trial will wait for a response indefinitely.
continue_after_response | boolean | true | If true, then the trial will end whenever the subject makes a response (assuming they make their response before the cutoff specified by the `timing_response` parameter). If false, then the trial will continue until the value for `timing_response` is reached. You can use this parameter to force the subject to view a stimulus for a fixed amount of time, even if they respond before the time is complete.
## Data Generated
In addition to the [default data collected by all plugins](), this plugin collects the following data for each trial.
Name | Type | Value
-----|------|------
stimulus | string | Either the path to the image file or the string containing the HTML formatted content that the subject saw on this trial.
key_press | numeric | Indicates which key the subject pressed. The value is the [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) corresponding to the subject's response.
rt | numeric | The response time in milliseconds for the subject to make a response. The time is measured from when the stimulus first appears on the screen until the subject's response.
## Examples
These examples show how to define a block using the single-stim plugin to achieve various goals.
#### Displaying images until subject gives a response
```javascript
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.png', 'img/sad_face.png']
}
```
#### Restricting which keys the subject can use to respond
```javascript
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.png', 'img/sad_face.png'],
choices: ['h','s']
}
```
#### Displaying HTML content for a fixed length of time
```javascript
var block = {
type: 'single-stim',
stimuli: ['<p>Radio</p>', '<p>Towel</p>', '<p>Match</p>'],
is_html: true,
timing_response: 1500,
continue_after_response: false
}
```

View File

@ -0,0 +1,64 @@
# jspsych-single-stim plugin
This plugin displays an image or HTML-formatted content and allows the subject to respond by pressing a key on the keyboard. The stimulus can be displayed until a response is given, or for a pre-determined amount of time. The trial can be ended automatically if the subject has failed to respond within a fixed length of time.
Because this plugin can display any HTML content, it is quite versatile. It can be used for any situation in which the response generated by the subject is a single keystroke.
## Parameters
This table lists the parameters associated with this plugin. Parameters with a default value of *undefined* must be specified. Other parameters can be left unspecified if the default value is acceptable.
Parameter | Type | Default Value | Description
----------|------|---------------|------------
stimuli | array | *undefined* | Each element of the array is a stimulus. A stimulus can be either a path to an image file or a string containing valid HTML markup. Each stimulus will be presented in its own trial, and thus the length of this array determines the total number of trials.
is_html | boolean | false | If the elements of the `stimuli` array are strings containing HTML content, then this parameter must be set to true.
choices | array | [ ] | This array contains the keys that the subject is allowed to press in order to respond to the stimulus. Keys can be specified as their [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) or as characters (e.g. `'a'`, `'q'`). The default value of an empty array means that all keys will be accepted as valid responses.
prompt | string | "" | This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that it can be used to provide a reminder about the action the subject is supposed to take (e.g. which key to press).
timing_stim | numeric | -1 | How long to show the stimulus for in milliseconds. If the value is -1, then the stimulus will be shown until the subject makes a response.
timing_response | numeric | -1 | How long to wait for the subject to make a response before ending the trial in milliseconds. If the subject fails to make a response before this timer is reached, the the subject's response will be recorded as -1 for the trial and the trial will end. If the value of this parameter is -1, then the trial will wait for a response indefinitely.
continue_after_response | boolean | true | If true, then the trial will end whenever the subject makes a response (assuming they make their response before the cutoff specified by the `timing_response` parameter). If false, then the trial will continue until the value for `timing_response` is reached. You can use this parameter to force the subject to view a stimulus for a fixed amount of time, even if they respond before the time is complete.
## Data Generated
In addition to the [default data collected by all plugins](), this plugin collects the following data for each trial.
Name | Type | Value
-----|------|------
stimulus | string | Either the path to the image file or the string containing the HTML formatted content that the subject saw on this trial.
key_press | numeric | Indicates which key the subject pressed. The value is the [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) corresponding to the subject's response.
rt | numeric | The response time in milliseconds for the subject to make a response. The time is measured from when the stimulus first appears on the screen until the subject's response.
## Examples
These examples show how to define a block using the single-stim plugin to achieve various goals.
#### Displaying images until subject gives a response
```javascript
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.png', 'img/sad_face.png']
}
```
#### Restricting which keys the subject can use to respond
```javascript
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.png', 'img/sad_face.png'],
choices: ['h','s']
}
```
#### Displaying HTML content for a fixed length of time
```javascript
var block = {
type: 'single-stim',
stimuli: ['<p>Radio</p>', '<p>Towel</p>', '<p>Match</p>'],
is_html: true,
timing_response: 1500,
continue_after_response: false
}
```

View File

@ -0,0 +1,64 @@
# jspsych-single-stim plugin
This plugin displays an image or HTML-formatted content and allows the subject to respond by pressing a key on the keyboard. The stimulus can be displayed until a response is given, or for a pre-determined amount of time. The trial can be ended automatically if the subject has failed to respond within a fixed length of time.
Because this plugin can display any HTML content, it is quite versatile. It can be used for any situation in which the response generated by the subject is a single keystroke.
## Parameters
This table lists the parameters associated with this plugin. Parameters with a default value of *undefined* must be specified. Other parameters can be left unspecified if the default value is acceptable.
Parameter | Type | Default Value | Description
----------|------|---------------|------------
stimuli | array | *undefined* | Each element of the array is a stimulus. A stimulus can be either a path to an image file or a string containing valid HTML markup. Each stimulus will be presented in its own trial, and thus the length of this array determines the total number of trials.
is_html | boolean | false | If the elements of the `stimuli` array are strings containing HTML content, then this parameter must be set to true.
choices | array | [ ] | This array contains the keys that the subject is allowed to press in order to respond to the stimulus. Keys can be specified as their [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) or as characters (e.g. `'a'`, `'q'`). The default value of an empty array means that all keys will be accepted as valid responses.
prompt | string | "" | This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that it can be used to provide a reminder about the action the subject is supposed to take (e.g. which key to press).
timing_stim | numeric | -1 | How long to show the stimulus for in milliseconds. If the value is -1, then the stimulus will be shown until the subject makes a response.
timing_response | numeric | -1 | How long to wait for the subject to make a response before ending the trial in milliseconds. If the subject fails to make a response before this timer is reached, the the subject's response will be recorded as -1 for the trial and the trial will end. If the value of this parameter is -1, then the trial will wait for a response indefinitely.
continue_after_response | boolean | true | If true, then the trial will end whenever the subject makes a response (assuming they make their response before the cutoff specified by the `timing_response` parameter). If false, then the trial will continue until the value for `timing_response` is reached. You can use this parameter to force the subject to view a stimulus for a fixed amount of time, even if they respond before the time is complete.
## Data Generated
In addition to the [default data collected by all plugins](), this plugin collects the following data for each trial.
Name | Type | Value
-----|------|------
stimulus | string | Either the path to the image file or the string containing the HTML formatted content that the subject saw on this trial.
key_press | numeric | Indicates which key the subject pressed. The value is the [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) corresponding to the subject's response.
rt | numeric | The response time in milliseconds for the subject to make a response. The time is measured from when the stimulus first appears on the screen until the subject's response.
## Examples
These examples show how to define a block using the single-stim plugin to achieve various goals.
#### Displaying images until subject gives a response
```javascript
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.png', 'img/sad_face.png']
}
```
#### Restricting which keys the subject can use to respond
```javascript
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.png', 'img/sad_face.png'],
choices: ['h','s']
}
```
#### Displaying HTML content for a fixed length of time
```javascript
var block = {
type: 'single-stim',
stimuli: ['<p>Radio</p>', '<p>Towel</p>', '<p>Match</p>'],
is_html: true,
timing_response: 1500,
continue_after_response: false
}
```

View File

@ -0,0 +1,64 @@
# jspsych-single-stim plugin
This plugin displays an image or HTML-formatted content and allows the subject to respond by pressing a key on the keyboard. The stimulus can be displayed until a response is given, or for a pre-determined amount of time. The trial can be ended automatically if the subject has failed to respond within a fixed length of time.
Because this plugin can display any HTML content, it is quite versatile. It can be used for any situation in which the response generated by the subject is a single keystroke.
## Parameters
This table lists the parameters associated with this plugin. Parameters with a default value of *undefined* must be specified. Other parameters can be left unspecified if the default value is acceptable.
Parameter | Type | Default Value | Description
----------|------|---------------|------------
stimuli | array | *undefined* | Each element of the array is a stimulus. A stimulus can be either a path to an image file or a string containing valid HTML markup. Each stimulus will be presented in its own trial, and thus the length of this array determines the total number of trials.
is_html | boolean | false | If the elements of the `stimuli` array are strings containing HTML content, then this parameter must be set to true.
choices | array | [ ] | This array contains the keys that the subject is allowed to press in order to respond to the stimulus. Keys can be specified as their [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) or as characters (e.g. `'a'`, `'q'`). The default value of an empty array means that all keys will be accepted as valid responses.
prompt | string | "" | This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that it can be used to provide a reminder about the action the subject is supposed to take (e.g. which key to press).
timing_stim | numeric | -1 | How long to show the stimulus for in milliseconds. If the value is -1, then the stimulus will be shown until the subject makes a response.
timing_response | numeric | -1 | How long to wait for the subject to make a response before ending the trial in milliseconds. If the subject fails to make a response before this timer is reached, the the subject's response will be recorded as -1 for the trial and the trial will end. If the value of this parameter is -1, then the trial will wait for a response indefinitely.
continue_after_response | boolean | true | If true, then the trial will end whenever the subject makes a response (assuming they make their response before the cutoff specified by the `timing_response` parameter). If false, then the trial will continue until the value for `timing_response` is reached. You can use this parameter to force the subject to view a stimulus for a fixed amount of time, even if they respond before the time is complete.
## Data Generated
In addition to the [default data collected by all plugins](), this plugin collects the following data for each trial.
Name | Type | Value
-----|------|------
stimulus | string | Either the path to the image file or the string containing the HTML formatted content that the subject saw on this trial.
key_press | numeric | Indicates which key the subject pressed. The value is the [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) corresponding to the subject's response.
rt | numeric | The response time in milliseconds for the subject to make a response. The time is measured from when the stimulus first appears on the screen until the subject's response.
## Examples
These examples show how to define a block using the single-stim plugin to achieve various goals.
#### Displaying images until subject gives a response
```javascript
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.png', 'img/sad_face.png']
}
```
#### Restricting which keys the subject can use to respond
```javascript
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.png', 'img/sad_face.png'],
choices: ['h','s']
}
```
#### Displaying HTML content for a fixed length of time
```javascript
var block = {
type: 'single-stim',
stimuli: ['<p>Radio</p>', '<p>Towel</p>', '<p>Match</p>'],
is_html: true,
timing_response: 1500,
continue_after_response: false
}
```

View File

@ -0,0 +1,64 @@
# jspsych-single-stim plugin
This plugin displays an image or HTML-formatted content and allows the subject to respond by pressing a key on the keyboard. The stimulus can be displayed until a response is given, or for a pre-determined amount of time. The trial can be ended automatically if the subject has failed to respond within a fixed length of time.
Because this plugin can display any HTML content, it is quite versatile. It can be used for any situation in which the response generated by the subject is a single keystroke.
## Parameters
This table lists the parameters associated with this plugin. Parameters with a default value of *undefined* must be specified. Other parameters can be left unspecified if the default value is acceptable.
Parameter | Type | Default Value | Description
----------|------|---------------|------------
stimuli | array | *undefined* | Each element of the array is a stimulus. A stimulus can be either a path to an image file or a string containing valid HTML markup. Each stimulus will be presented in its own trial, and thus the length of this array determines the total number of trials.
is_html | boolean | false | If the elements of the `stimuli` array are strings containing HTML content, then this parameter must be set to true.
choices | array | [ ] | This array contains the keys that the subject is allowed to press in order to respond to the stimulus. Keys can be specified as their [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) or as characters (e.g. `'a'`, `'q'`). The default value of an empty array means that all keys will be accepted as valid responses.
prompt | string | "" | This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that it can be used to provide a reminder about the action the subject is supposed to take (e.g. which key to press).
timing_stim | numeric | -1 | How long to show the stimulus for in milliseconds. If the value is -1, then the stimulus will be shown until the subject makes a response.
timing_response | numeric | -1 | How long to wait for the subject to make a response before ending the trial in milliseconds. If the subject fails to make a response before this timer is reached, the the subject's response will be recorded as -1 for the trial and the trial will end. If the value of this parameter is -1, then the trial will wait for a response indefinitely.
continue_after_response | boolean | true | If true, then the trial will end whenever the subject makes a response (assuming they make their response before the cutoff specified by the `timing_response` parameter). If false, then the trial will continue until the value for `timing_response` is reached. You can use this parameter to force the subject to view a stimulus for a fixed amount of time, even if they respond before the time is complete.
## Data Generated
In addition to the [default data collected by all plugins](), this plugin collects the following data for each trial.
Name | Type | Value
-----|------|------
stimulus | string | Either the path to the image file or the string containing the HTML formatted content that the subject saw on this trial.
key_press | numeric | Indicates which key the subject pressed. The value is the [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) corresponding to the subject's response.
rt | numeric | The response time in milliseconds for the subject to make a response. The time is measured from when the stimulus first appears on the screen until the subject's response.
## Examples
These examples show how to define a block using the single-stim plugin to achieve various goals.
#### Displaying images until subject gives a response
```javascript
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.png', 'img/sad_face.png']
}
```
#### Restricting which keys the subject can use to respond
```javascript
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.png', 'img/sad_face.png'],
choices: ['h','s']
}
```
#### Displaying HTML content for a fixed length of time
```javascript
var block = {
type: 'single-stim',
stimuli: ['<p>Radio</p>', '<p>Towel</p>', '<p>Match</p>'],
is_html: true,
timing_response: 1500,
continue_after_response: false
}
```

View File

@ -0,0 +1,64 @@
# jspsych-single-stim plugin
This plugin displays an image or HTML-formatted content and allows the subject to respond by pressing a key on the keyboard. The stimulus can be displayed until a response is given, or for a pre-determined amount of time. The trial can be ended automatically if the subject has failed to respond within a fixed length of time.
Because this plugin can display any HTML content, it is quite versatile. It can be used for any situation in which the response generated by the subject is a single keystroke.
## Parameters
This table lists the parameters associated with this plugin. Parameters with a default value of *undefined* must be specified. Other parameters can be left unspecified if the default value is acceptable.
Parameter | Type | Default Value | Description
----------|------|---------------|------------
stimuli | array | *undefined* | Each element of the array is a stimulus. A stimulus can be either a path to an image file or a string containing valid HTML markup. Each stimulus will be presented in its own trial, and thus the length of this array determines the total number of trials.
is_html | boolean | false | If the elements of the `stimuli` array are strings containing HTML content, then this parameter must be set to true.
choices | array | [ ] | This array contains the keys that the subject is allowed to press in order to respond to the stimulus. Keys can be specified as their [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) or as characters (e.g. `'a'`, `'q'`). The default value of an empty array means that all keys will be accepted as valid responses.
prompt | string | "" | This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that it can be used to provide a reminder about the action the subject is supposed to take (e.g. which key to press).
timing_stim | numeric | -1 | How long to show the stimulus for in milliseconds. If the value is -1, then the stimulus will be shown until the subject makes a response.
timing_response | numeric | -1 | How long to wait for the subject to make a response before ending the trial in milliseconds. If the subject fails to make a response before this timer is reached, the the subject's response will be recorded as -1 for the trial and the trial will end. If the value of this parameter is -1, then the trial will wait for a response indefinitely.
continue_after_response | boolean | true | If true, then the trial will end whenever the subject makes a response (assuming they make their response before the cutoff specified by the `timing_response` parameter). If false, then the trial will continue until the value for `timing_response` is reached. You can use this parameter to force the subject to view a stimulus for a fixed amount of time, even if they respond before the time is complete.
## Data Generated
In addition to the [default data collected by all plugins](), this plugin collects the following data for each trial.
Name | Type | Value
-----|------|------
stimulus | string | Either the path to the image file or the string containing the HTML formatted content that the subject saw on this trial.
key_press | numeric | Indicates which key the subject pressed. The value is the [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) corresponding to the subject's response.
rt | numeric | The response time in milliseconds for the subject to make a response. The time is measured from when the stimulus first appears on the screen until the subject's response.
## Examples
These examples show how to define a block using the single-stim plugin to achieve various goals.
#### Displaying images until subject gives a response
```javascript
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.png', 'img/sad_face.png']
}
```
#### Restricting which keys the subject can use to respond
```javascript
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.png', 'img/sad_face.png'],
choices: ['h','s']
}
```
#### Displaying HTML content for a fixed length of time
```javascript
var block = {
type: 'single-stim',
stimuli: ['<p>Radio</p>', '<p>Towel</p>', '<p>Match</p>'],
is_html: true,
timing_response: 1500,
continue_after_response: false
}
```

View File

@ -0,0 +1,64 @@
# jspsych-single-stim plugin
This plugin displays an image or HTML-formatted content and allows the subject to respond by pressing a key on the keyboard. The stimulus can be displayed until a response is given, or for a pre-determined amount of time. The trial can be ended automatically if the subject has failed to respond within a fixed length of time.
Because this plugin can display any HTML content, it is quite versatile. It can be used for any situation in which the response generated by the subject is a single keystroke.
## Parameters
This table lists the parameters associated with this plugin. Parameters with a default value of *undefined* must be specified. Other parameters can be left unspecified if the default value is acceptable.
Parameter | Type | Default Value | Description
----------|------|---------------|------------
stimuli | array | *undefined* | Each element of the array is a stimulus. A stimulus can be either a path to an image file or a string containing valid HTML markup. Each stimulus will be presented in its own trial, and thus the length of this array determines the total number of trials.
is_html | boolean | false | If the elements of the `stimuli` array are strings containing HTML content, then this parameter must be set to true.
choices | array | [ ] | This array contains the keys that the subject is allowed to press in order to respond to the stimulus. Keys can be specified as their [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) or as characters (e.g. `'a'`, `'q'`). The default value of an empty array means that all keys will be accepted as valid responses.
prompt | string | "" | This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that it can be used to provide a reminder about the action the subject is supposed to take (e.g. which key to press).
timing_stim | numeric | -1 | How long to show the stimulus for in milliseconds. If the value is -1, then the stimulus will be shown until the subject makes a response.
timing_response | numeric | -1 | How long to wait for the subject to make a response before ending the trial in milliseconds. If the subject fails to make a response before this timer is reached, the the subject's response will be recorded as -1 for the trial and the trial will end. If the value of this parameter is -1, then the trial will wait for a response indefinitely.
continue_after_response | boolean | true | If true, then the trial will end whenever the subject makes a response (assuming they make their response before the cutoff specified by the `timing_response` parameter). If false, then the trial will continue until the value for `timing_response` is reached. You can use this parameter to force the subject to view a stimulus for a fixed amount of time, even if they respond before the time is complete.
## Data Generated
In addition to the [default data collected by all plugins](), this plugin collects the following data for each trial.
Name | Type | Value
-----|------|------
stimulus | string | Either the path to the image file or the string containing the HTML formatted content that the subject saw on this trial.
key_press | numeric | Indicates which key the subject pressed. The value is the [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) corresponding to the subject's response.
rt | numeric | The response time in milliseconds for the subject to make a response. The time is measured from when the stimulus first appears on the screen until the subject's response.
## Examples
These examples show how to define a block using the single-stim plugin to achieve various goals.
#### Displaying images until subject gives a response
```javascript
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.png', 'img/sad_face.png']
}
```
#### Restricting which keys the subject can use to respond
```javascript
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.png', 'img/sad_face.png'],
choices: ['h','s']
}
```
#### Displaying HTML content for a fixed length of time
```javascript
var block = {
type: 'single-stim',
stimuli: ['<p>Radio</p>', '<p>Towel</p>', '<p>Match</p>'],
is_html: true,
timing_response: 1500,
continue_after_response: false
}
```

View File

@ -0,0 +1,64 @@
# jspsych-single-stim plugin
This plugin displays an image or HTML-formatted content and allows the subject to respond by pressing a key on the keyboard. The stimulus can be displayed until a response is given, or for a pre-determined amount of time. The trial can be ended automatically if the subject has failed to respond within a fixed length of time.
Because this plugin can display any HTML content, it is quite versatile. It can be used for any situation in which the response generated by the subject is a single keystroke.
## Parameters
This table lists the parameters associated with this plugin. Parameters with a default value of *undefined* must be specified. Other parameters can be left unspecified if the default value is acceptable.
Parameter | Type | Default Value | Description
----------|------|---------------|------------
stimuli | array | *undefined* | Each element of the array is a stimulus. A stimulus can be either a path to an image file or a string containing valid HTML markup. Each stimulus will be presented in its own trial, and thus the length of this array determines the total number of trials.
is_html | boolean | false | If the elements of the `stimuli` array are strings containing HTML content, then this parameter must be set to true.
choices | array | [ ] | This array contains the keys that the subject is allowed to press in order to respond to the stimulus. Keys can be specified as their [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) or as characters (e.g. `'a'`, `'q'`). The default value of an empty array means that all keys will be accepted as valid responses.
prompt | string | "" | This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that it can be used to provide a reminder about the action the subject is supposed to take (e.g. which key to press).
timing_stim | numeric | -1 | How long to show the stimulus for in milliseconds. If the value is -1, then the stimulus will be shown until the subject makes a response.
timing_response | numeric | -1 | How long to wait for the subject to make a response before ending the trial in milliseconds. If the subject fails to make a response before this timer is reached, the the subject's response will be recorded as -1 for the trial and the trial will end. If the value of this parameter is -1, then the trial will wait for a response indefinitely.
continue_after_response | boolean | true | If true, then the trial will end whenever the subject makes a response (assuming they make their response before the cutoff specified by the `timing_response` parameter). If false, then the trial will continue until the value for `timing_response` is reached. You can use this parameter to force the subject to view a stimulus for a fixed amount of time, even if they respond before the time is complete.
## Data Generated
In addition to the [default data collected by all plugins](), this plugin collects the following data for each trial.
Name | Type | Value
-----|------|------
stimulus | string | Either the path to the image file or the string containing the HTML formatted content that the subject saw on this trial.
key_press | numeric | Indicates which key the subject pressed. The value is the [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) corresponding to the subject's response.
rt | numeric | The response time in milliseconds for the subject to make a response. The time is measured from when the stimulus first appears on the screen until the subject's response.
## Examples
These examples show how to define a block using the single-stim plugin to achieve various goals.
#### Displaying images until subject gives a response
```javascript
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.png', 'img/sad_face.png']
}
```
#### Restricting which keys the subject can use to respond
```javascript
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.png', 'img/sad_face.png'],
choices: ['h','s']
}
```
#### Displaying HTML content for a fixed length of time
```javascript
var block = {
type: 'single-stim',
stimuli: ['<p>Radio</p>', '<p>Towel</p>', '<p>Match</p>'],
is_html: true,
timing_response: 1500,
continue_after_response: false
}
```

View File

@ -0,0 +1,64 @@
# jspsych-single-stim plugin
This plugin displays an image or HTML-formatted content and allows the subject to respond by pressing a key on the keyboard. The stimulus can be displayed until a response is given, or for a pre-determined amount of time. The trial can be ended automatically if the subject has failed to respond within a fixed length of time.
Because this plugin can display any HTML content, it is quite versatile. It can be used for any situation in which the response generated by the subject is a single keystroke.
## Parameters
This table lists the parameters associated with this plugin. Parameters with a default value of *undefined* must be specified. Other parameters can be left unspecified if the default value is acceptable.
Parameter | Type | Default Value | Description
----------|------|---------------|------------
stimuli | array | *undefined* | Each element of the array is a stimulus. A stimulus can be either a path to an image file or a string containing valid HTML markup. Each stimulus will be presented in its own trial, and thus the length of this array determines the total number of trials.
is_html | boolean | false | If the elements of the `stimuli` array are strings containing HTML content, then this parameter must be set to true.
choices | array | [ ] | This array contains the keys that the subject is allowed to press in order to respond to the stimulus. Keys can be specified as their [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) or as characters (e.g. `'a'`, `'q'`). The default value of an empty array means that all keys will be accepted as valid responses.
prompt | string | "" | This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that it can be used to provide a reminder about the action the subject is supposed to take (e.g. which key to press).
timing_stim | numeric | -1 | How long to show the stimulus for in milliseconds. If the value is -1, then the stimulus will be shown until the subject makes a response.
timing_response | numeric | -1 | How long to wait for the subject to make a response before ending the trial in milliseconds. If the subject fails to make a response before this timer is reached, the the subject's response will be recorded as -1 for the trial and the trial will end. If the value of this parameter is -1, then the trial will wait for a response indefinitely.
continue_after_response | boolean | true | If true, then the trial will end whenever the subject makes a response (assuming they make their response before the cutoff specified by the `timing_response` parameter). If false, then the trial will continue until the value for `timing_response` is reached. You can use this parameter to force the subject to view a stimulus for a fixed amount of time, even if they respond before the time is complete.
## Data Generated
In addition to the [default data collected by all plugins](), this plugin collects the following data for each trial.
Name | Type | Value
-----|------|------
stimulus | string | Either the path to the image file or the string containing the HTML formatted content that the subject saw on this trial.
key_press | numeric | Indicates which key the subject pressed. The value is the [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) corresponding to the subject's response.
rt | numeric | The response time in milliseconds for the subject to make a response. The time is measured from when the stimulus first appears on the screen until the subject's response.
## Examples
These examples show how to define a block using the single-stim plugin to achieve various goals.
#### Displaying images until subject gives a response
```javascript
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.png', 'img/sad_face.png']
}
```
#### Restricting which keys the subject can use to respond
```javascript
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.png', 'img/sad_face.png'],
choices: ['h','s']
}
```
#### Displaying HTML content for a fixed length of time
```javascript
var block = {
type: 'single-stim',
stimuli: ['<p>Radio</p>', '<p>Towel</p>', '<p>Match</p>'],
is_html: true,
timing_response: 1500,
continue_after_response: false
}
```

View File

@ -0,0 +1,64 @@
# jspsych-single-stim plugin
This plugin displays an image or HTML-formatted content and allows the subject to respond by pressing a key on the keyboard. The stimulus can be displayed until a response is given, or for a pre-determined amount of time. The trial can be ended automatically if the subject has failed to respond within a fixed length of time.
Because this plugin can display any HTML content, it is quite versatile. It can be used for any situation in which the response generated by the subject is a single keystroke.
## Parameters
This table lists the parameters associated with this plugin. Parameters with a default value of *undefined* must be specified. Other parameters can be left unspecified if the default value is acceptable.
Parameter | Type | Default Value | Description
----------|------|---------------|------------
stimuli | array | *undefined* | Each element of the array is a stimulus. A stimulus can be either a path to an image file or a string containing valid HTML markup. Each stimulus will be presented in its own trial, and thus the length of this array determines the total number of trials.
is_html | boolean | false | If the elements of the `stimuli` array are strings containing HTML content, then this parameter must be set to true.
choices | array | [ ] | This array contains the keys that the subject is allowed to press in order to respond to the stimulus. Keys can be specified as their [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) or as characters (e.g. `'a'`, `'q'`). The default value of an empty array means that all keys will be accepted as valid responses.
prompt | string | "" | This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that it can be used to provide a reminder about the action the subject is supposed to take (e.g. which key to press).
timing_stim | numeric | -1 | How long to show the stimulus for in milliseconds. If the value is -1, then the stimulus will be shown until the subject makes a response.
timing_response | numeric | -1 | How long to wait for the subject to make a response before ending the trial in milliseconds. If the subject fails to make a response before this timer is reached, the the subject's response will be recorded as -1 for the trial and the trial will end. If the value of this parameter is -1, then the trial will wait for a response indefinitely.
continue_after_response | boolean | true | If true, then the trial will end whenever the subject makes a response (assuming they make their response before the cutoff specified by the `timing_response` parameter). If false, then the trial will continue until the value for `timing_response` is reached. You can use this parameter to force the subject to view a stimulus for a fixed amount of time, even if they respond before the time is complete.
## Data Generated
In addition to the [default data collected by all plugins](), this plugin collects the following data for each trial.
Name | Type | Value
-----|------|------
stimulus | string | Either the path to the image file or the string containing the HTML formatted content that the subject saw on this trial.
key_press | numeric | Indicates which key the subject pressed. The value is the [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) corresponding to the subject's response.
rt | numeric | The response time in milliseconds for the subject to make a response. The time is measured from when the stimulus first appears on the screen until the subject's response.
## Examples
These examples show how to define a block using the single-stim plugin to achieve various goals.
#### Displaying images until subject gives a response
```javascript
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.png', 'img/sad_face.png']
}
```
#### Restricting which keys the subject can use to respond
```javascript
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.png', 'img/sad_face.png'],
choices: ['h','s']
}
```
#### Displaying HTML content for a fixed length of time
```javascript
var block = {
type: 'single-stim',
stimuli: ['<p>Radio</p>', '<p>Towel</p>', '<p>Match</p>'],
is_html: true,
timing_response: 1500,
continue_after_response: false
}
```

View File

@ -0,0 +1,64 @@
# jspsych-single-stim plugin
This plugin displays an image or HTML-formatted content and allows the subject to respond by pressing a key on the keyboard. The stimulus can be displayed until a response is given, or for a pre-determined amount of time. The trial can be ended automatically if the subject has failed to respond within a fixed length of time.
Because this plugin can display any HTML content, it is quite versatile. It can be used for any situation in which the response generated by the subject is a single keystroke.
## Parameters
This table lists the parameters associated with this plugin. Parameters with a default value of *undefined* must be specified. Other parameters can be left unspecified if the default value is acceptable.
Parameter | Type | Default Value | Description
----------|------|---------------|------------
stimuli | array | *undefined* | Each element of the array is a stimulus. A stimulus can be either a path to an image file or a string containing valid HTML markup. Each stimulus will be presented in its own trial, and thus the length of this array determines the total number of trials.
is_html | boolean | false | If the elements of the `stimuli` array are strings containing HTML content, then this parameter must be set to true.
choices | array | [ ] | This array contains the keys that the subject is allowed to press in order to respond to the stimulus. Keys can be specified as their [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) or as characters (e.g. `'a'`, `'q'`). The default value of an empty array means that all keys will be accepted as valid responses.
prompt | string | "" | This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that it can be used to provide a reminder about the action the subject is supposed to take (e.g. which key to press).
timing_stim | numeric | -1 | How long to show the stimulus for in milliseconds. If the value is -1, then the stimulus will be shown until the subject makes a response.
timing_response | numeric | -1 | How long to wait for the subject to make a response before ending the trial in milliseconds. If the subject fails to make a response before this timer is reached, the the subject's response will be recorded as -1 for the trial and the trial will end. If the value of this parameter is -1, then the trial will wait for a response indefinitely.
continue_after_response | boolean | true | If true, then the trial will end whenever the subject makes a response (assuming they make their response before the cutoff specified by the `timing_response` parameter). If false, then the trial will continue until the value for `timing_response` is reached. You can use this parameter to force the subject to view a stimulus for a fixed amount of time, even if they respond before the time is complete.
## Data Generated
In addition to the [default data collected by all plugins](), this plugin collects the following data for each trial.
Name | Type | Value
-----|------|------
stimulus | string | Either the path to the image file or the string containing the HTML formatted content that the subject saw on this trial.
key_press | numeric | Indicates which key the subject pressed. The value is the [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) corresponding to the subject's response.
rt | numeric | The response time in milliseconds for the subject to make a response. The time is measured from when the stimulus first appears on the screen until the subject's response.
## Examples
These examples show how to define a block using the single-stim plugin to achieve various goals.
#### Displaying images until subject gives a response
```javascript
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.png', 'img/sad_face.png']
}
```
#### Restricting which keys the subject can use to respond
```javascript
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.png', 'img/sad_face.png'],
choices: ['h','s']
}
```
#### Displaying HTML content for a fixed length of time
```javascript
var block = {
type: 'single-stim',
stimuli: ['<p>Radio</p>', '<p>Towel</p>', '<p>Match</p>'],
is_html: true,
timing_response: 1500,
continue_after_response: false
}
```

View File

@ -0,0 +1,61 @@
# Plugins
In jsPsych, plugins define the kinds of tasks that subjects perform in experiments. Some plugins define very general tasks, like displaying instructions or displaying a visual stimulus and getting a keyboard response. Other plugins are more specific, displaying particular kinds of interactive stimuli, or running a specific kind of perceptual discrimination task. Creating an experiment with jsPsych involves figuring out which plugins are needed for the kinds of tasks you want to have your subjects perform.
Plugins provide a structure for a particular task. For example, the `jspsych-single-stim` plugin defines a simple structure for showing a visual stimulus and collecting a keyboard response. To use the plugin, you need to specify the content, such as what the stimulus is, what keys the subject is allowed to press, and how long the stimulus should be on the screen. Many of these content options have reasonable default values; even though the `jspsych-single-stim` plugin has many different options, you only *need* to specify the stimulus in order to use it. Each plugin has its own documentation page, which describes what the plugin does and what options are available.
## Using a plugin
To use a plugin, you'll need to load the plugin's JavaScript file on your experiment page:
```html
<script src="jspsych/plugins/jspsych-single-stim.js" type="text/javascript"></script>
```
Once a plugin is loaded, you can define a block that uses that plugin. The following JavaScript code defines a trial using the `jspsych-single-stim` plugin to display an image file ('images/happy_face.jpg'). This trial uses the default values for valid keys, length of display, and so on. You could override these values by adding them to the object.
```javascript
var single_stim_block = {
type: 'single-stim',
stimuli: 'images/happy_face.jpg'
}
```
Here's an exampe of overriding the default value for `timing_post_trial`:
```javascript
var single_stim_block = {
type: 'single-stim',
stimuli: 'images/happy_face.jpg',
timing_post_trial: 2000
}
```
## List of available plugins
This table is a description of all plugins that are currently bundled with jsPsych. Click on the name of a plugin to view its documentation page.
Plugin | Description
------ | -----------
[jspsych&#8209;animation](plugins/jspsych-animation) | Shows a sequence of images at a specified frame rate. Records key presses (including timing information) made by the subject while they are viewing the animation.
[jspsych&#8209;call&#8209;function](plugins/jspsych-call-function) | Executes an arbitrary function call. Doesn't display anything to the subject, and the subject is usually unaware that this plugin has even executed. It's useful for performing tasks at specified times in the experiment, such as saving data.
[jspsych&#8209;categorize](plugins/jspsych-categorize) | The subject responds to a stimulus using the keyboard and can be given feedback about the correctness of their response.
[jspsych&#8209;categorize&#8209;animation](plugins/jspsych-categorize-animation) | A mash-up of the animation and categorize plugin. The subject responds to an animation and can be given feedback about their response.
[jspsych&#8209;free&#8209;sort](plugins/jspsych-free-sort) | Displays a set of images on the screen in random locations. Subjects can click and drag the images to move them around the screen. Records all the moves made by the subject, so the sequence of moves can be recovered from the data.
[jspsych&#8209;html](plugins/jspsych-html) | Displays an external HTML page (such as a consent form) and lets the subject respond by clicking a button or pressing a key. Plugin can validate their response, which is useful for making sure that a subject has granted consent before starting the experiment.
[jspsych&#8209;palmer](plugins/jspsych-palmer) | Shows grid-like stimuli inspired by Stephen Palmer's work. The stimuli are editable: subjects can add and subtract parts interactively. Also contains a method for generating the HTML code to render the stimuli, allowing them to be used in other plugins.
[jspsych&#8209;same&#8209;different](plugins/jspsych-same-different) | A same-different judgment task. A stimulus is shown, followed by a brief gap, and then another stimulus is shown. The subject indicates whether the stimuli are the same or different.
[jspsych&#8209;similarity](plugins/jspsych-similarity) | Two stimuli are shown sequentially, and the subject indicates how similar they are by dragging a slider object.
[jspsych&#8209;single&#8209;stim](plugins/jspsych-single-stim) | A basic plugin for displaying a stimulus and getting a keyboard response.
[jspsych&#8209;survey&#8209;likert](plugins/jspsych-survey-likert) | Displays likert-style questions. The subject responds by dragging a slider.
[jspsych&#8209;survey&#8209;text](plugins/jspsych-survey-text) | Shows a prompt with a text box. The subject writes a response and then submits by clicking a button.
[jspsych&#8209;text](plugins/jspsych-text) | Shows HTML-formatted text on the screen.
[jspsych&#8209;visual&#8209;search&#8209;circle](plugins/jspsych-visual-search-circle) | A customizable visual-search task modelled after [Wang, Cavanagh, & Green (1994)](http://dx.doi.org/10.3758/BF03206946). The subject indicates whether or not a target is present among a set of distractors. The stimuli are displayed in a circle, evenly-spaced, equidistant from a fixation point.
[jspsych&#8209;vsl&#8209;animate&#8209;occlusion](plugins/jspsych-vsl-animate-occlusion) | A visual statistical learning paradigm based on [Fiser & Aslin (2002)](http://dx.doi.org/10.1037//0278-7393.28.3.458). A sequence of stimuli are shown in an oscillatory motion. An occluding rectangle is in the center of the display, and the stimuli change when they are behind the rectangle.
[jspsych&#8209;vsl&#8209;grid&#8209;scene](plugins/jspsych-vsl-grid-scene) | A visual statistical learning paradigm based on [Fiser & Aslin (2001)](http://dx.doi.org/10.1111/1467-9280.00392). A scene made up of individual stimuli arranged in a grid is shown. This plugin can also generate the HTML code to render the stimuli for use in other plugins.
[jspsych&#8209;xab](plugins/jspsych-xab) | A two-alternative forced choice task. A target (X) is shown, followed by a brief gap, and then two choices (A & B) are displayed. The subject must pick whichever one matches X (matches is defined however the experimenter wishes; it could be a literal match, or it could be a match on some particular property).
## Creating a plugin
There are many plugins that are bundled with jsPsych, but you aren't limited by what's currently available. Creating a

View File

@ -0,0 +1,67 @@
# jsPsych
## Overview
jsPsych is a JavaScript library for creating and running behavioral experiments in a web browser. The library provides a flexible framework for building a wide range of laboratory-like experiments that can be run online.
jsPsych prvoides the *structure* for an experiment. It handles things like determining which trial to run next, storing data, and randomizing factors/order of presentation. It also provides a set of *plugins*, which are ready-made templates for simple experimental tasks like displaying instructions or displaying a stimulus and collecting a keyboard response. A full experiment created with jsPsych will be a collection of different plugins that define the different tasks that a subject will complete.
To build an experiment with jsPsych, you'll specify the structure of the experiment using JavaScript code. You'll also need to provide the *content* that defines your experiment, such as the actual text that subjects see when they are shown instructions and the images that they will view. You can also specify a wide-range of parameters to control things like stimulus duration, which keyboard keys subjects are allowed to press, and so on.
This page gives a broad overview of how jsPsych works. More detail is available on most of the topics on this page by using the navigation above, or by following the links within the documentation.
## Loading jsPsych
To use jsPsych, you'll need to load a few JavaScript files in an HTML document. At a minimum, you'll be loading three files: the jQuery library, the main jsPsych.js library, and at least one jsPsych plugin. A bare-bones jsPsych-ready document (with the single-stim plugin loaded) will look something like the following:
```html
<!doctype html>
<html>
<head>
<script src="js/jquery.js"></script>
<script src="js/jspsych/jspsych.js"></script>
<script src="js/jspsych/plugins/jspsych-single-stim.js"></script>
</head>
<body>
</body>
</html>
```
## Creating an experiment
To use jsPsych, you'll need to create a description of your experiment in JavaScript. This description is an array; each element of the array is a **block** or a **chunk**. Chunks and blocks are special objects in jsPsych. They define sets of trials that should be grouped together (learn more about [chunks and blocks]()).
```javascript
// defining an empty array to contain the experiment description
var experiment = [];
```
Blocks are created by defining a JavaScript object with a `type` property that corresponds to a particular [plugin](). The other properties of the block object will depend on which plugin is used. Each plugin has different options.
The code below will create a block that contains two trials. The first trial will display the image file `img/happy_face.jpg` and the second trial will display the image file `img/sad_face.jpg`.
```javascript
// create a block using the 'single-stim' plugin
var block = {
type: 'single-stim',
stimuli: ['img/happy_face.jpg','img/sad_face.jpg']
};
```
To add the block to the experiment description, we need to change the `experiment` array. There are several ways to do this in JavaScript, but we'll use the `.push()` function for generalizability.
```javascript
// add the block to the experiment description
experiment.push(block);
```
Once you have the experiment description defined, you can tell jsPsych to run the experiment by calling `jsPsych.init()` and passing your description as the value for the `experiment_structure` parameter:
```javascript
jsPsych.init({
experiment_structure: experiment
})
```
For a more in-depth tutorial about creating an experiment, take a look at the [tutorials]().

50
docs/mkdocs.yml Normal file
View File

@ -0,0 +1,50 @@
site_name: jsPsych
theme: flatly
repo_url: 'https://github.com/jodeleeuw/jsPsych'
repo_name: 'GitHub'
extra_css:
- css/extra.css
extra_javascript:
- js/extra.js
include_next_prev: false
docs_dir: markdown_docs
pages:
- ['index.md', 'Introduction']
- ['tutorials/flanker-task.md', 'Tutorials', 'Demo Experiment: Choice Response Time Task']
- ['tutorials/flanker-task.md', 'Tutorials', 'Demo Experiment: Flanker Task']
- ['core_library/overview.md', 'Core Library API', 'Overview']
- ['core_library/jspsych-core.md', 'Core Library API', 'jsPsych core']
- ['core_library/jspsych-data.md', 'Core Library API', 'jsPsych.data']
- ['core_library/jspsych-randomization.md', 'Core Library API', 'jsPsych.randomization']
- ['core_library/jspsych-mturk.md', 'Core Library API', 'jsPsych.mturk']
- ['core_library/jspsych-pluginAPI.md', 'Core Library API', 'jsPsych.pluginAPI']
- ['plugins/overview.md', 'Plugins', 'Overview']
- ['plugins/creating-a-plugin.md', 'Plugins', 'Creating a New Plugin']
- ['plugins/jspsych-animation.md', 'Plugins', 'jspsych-animation']
- ['plugins/jspsych-call-function.md', 'Plugins', 'jspsych-call-function']
- ['plugins/jspsych-categorize.md', 'Plugins', 'jspsych-categorize']
- ['plugins/jspsych-categorize-animation.md', 'Plugins', 'jspsych-categorize-animation']
- ['plugins/jspsych-free-sort.md', 'Plugins', 'jspsych-free-sort']
- ['plugins/jspsych-html.md', 'Plugins', 'jspsych-html']
- ['plugins/jspsych-palmer.md', 'Plugins', 'jspsych-palmer']
- ['plugins/jspsych-same-different.md', 'Plugins', 'jspsych-same-different']
- ['plugins/jspsych-similarity.md', 'Plugins', 'jspsych-similarity']
- ['plugins/jspsych-single-stim.md', 'Plugins', 'jspsych-single-stim']
- ['plugins/jspsych-suvey-likert.md', 'Plugins', 'jspsych-suvey-likert']
- ['plugins/jspsych-survey-text.md', 'Plugins', 'jspsych-survey-text']
- ['plugins/jspsych-text.md', 'Plugins', 'jspsych-text']
- ['plugins/jspsych-visual-search-circle.md', 'Plugins', 'jspsych-visual-search-circle']
- ['plugins/jspsych-vsl-animate-occlusion.md', 'Plugins', 'jspsych-vsl-animate-occlusion']
- ['plugins/jspsych-vsl-grid-scene.md', 'Plugins', 'jspsych-vsl-grid-scene']
- ['plugins/jspsych-xab.md', 'Plugins', 'jspsych-xab']
- ['features/chunks-blocks-trials.md', 'Features', 'Creating an Experiment: Chunks, Blocks, & Trials']
- ['features/progress-bar.md', 'Features', 'Automatic Progress Bar']
- ['features/mturk.md', 'Features', 'Integrating with Mechanical Turk']
- ['features/data.md', 'Features', 'Data Storage']
- ['features/randomization-repetition.md', 'Features', 'Randomization & Repetition']
- ['features/functions-as-parameters.md', 'Features', 'Using Functions as Plugin Parameters']
- ['features/data.md', 'Features', 'Event-related Callback Functions']
- ['features/image-preloading.md', 'Features', 'Image Preloading']
- ['about/about.md', 'About', 'About jsPsych']
- ['about/license.md', 'About', 'License']
- ['about/about.md', 'About', 'Contributing to jsPsych']