1.1.1 • Published 6 months ago

neurocog v1.1.1

Weekly downloads
-
License
CC-BY-NC-SA-4.0
Repository
github
Last release
6 months ago

Neurocog.js

Neurocog.js Icon

A jsPsych Extension enabling integration with the Gorilla online behavioral experiment platform, designed to extend your jsPsych experiment with new features and capabilities.

🚨 Neurocog.js is now a jsPsych Extension! This means that Neurocog.js v0.4.0+ is only compatible with jsPsych v7.0+. For earlier jsPsych versions, please use Neurocog.js v0.3.9 or earlier. 🚨


Features

Gorilla integration

Facilitates interaction with parts of the Gorilla API. Load and access stimuli, access manipulations, and update stored data while maintaining the same codebase online and offline. The wrapper library detects what context the experiment is running in and makes API calls accordingly.

State management

A global state is maintained outside of the jsPsych instance. While not an advisable for experiment-wide data storage, a state system can be used to direct task logic and add an element of dynamic behavior. Additionally, it could function as temporary data storage.

Error handling & task shutdown

By listening for errors in the browser, this library provides graceful error handling and alerts participants before ending the experiment. This prevents online experiments from hanging or resulting in the complete loss of participant data.

Centralised seeded random number generator

A seeded RNG is provided using the D3.js library.

Installation

jsPsych v7.0+

npm install neurocog
yarn add neurocog

Once installed, refer to the jsPsych guide on Extension usage for instructions to enable the Neurocog.js extension within your existing experiment using jsPsych v7.0+. Refer to Configuration below for further information regaring the expected parameters (params).

Up to jsPsych v7.0

npm install neurocog@0.3.9
yarn add neurocog@0.3.9

Configuration

Neurocog.js expects a number of parameters (params) when being initialized. There are also optional parameters (parameters in bold are required):

NameTypeDescription
namestringA human-readable name for the experiment such as "Brain Game"
studyNamestringA machine-readable name for the experiment plugin such as "brain-game". No whitespace is permitted.
allowParticipantContactbooleanWhether or not to show an email address for participants to contact in the case of an error.
contactstringThe contact email address for the experiment.
seednumberA float to act as the seed for the RNG.
statekey : valueState initialisation parameters. This object is digested as the initial state and is accessible during the experiment using the same keys. While not required, it must be at least defined if state functionality is to be used.
loggingLogLevelSet the logging level of the consola logging utility.

⚠️ Breaking Change (as of v1.1.0): Multiple parameters have been removed and are no longer utilized. This has also been reflected in a number of functions that have been deprecated. This table describes the parameters that have been removed in v1.1.0.

NameTypeDescription
manipulationskey : valueA collection of key-value pairs that represent the manipulations configured in Gorilla. The key must be a string, and the value can be a string, boolean, or number. While required, it can be empty.
resourceskey : valueA collection of key-value pairs that represent resources used in the experiment. The key can be used as a unique identifier for accessing the resource in the source code. The value is the relative path to the actual resource. While required, it can be empty.
stimulikey : valueA collection of key-value pairs that represent the stimuli used in the experiment. The key can be used as a unique identifier for accessing the stimulus in the source code. The value is the relative path to the actual stimulus. While required, it can be empty.

Integration

To utilize the Neurocog.js functionality in timeline trials, ensure that the trial object contains the extensions parameter containing the type NeurocogExtension, shown below:

var timelineNode = {
  ...
  extensions: [
    {
      type: NeurocogExtension,
    }
  ],
  ...
}

Check out the experiment in the example/ directory for a simple example.

Gorilla: Manipulations

⚠️ Breaking Change (as of v1.1.0): Manipulations are no longer required to be specified in the Neurocog parameters. Now the getManipulation function takes two arguments, the name, and a default value. If running locally, the default value will always be returned. If running on Gorilla, the Manipulation value specified on Gorilla will be returned.

Accessing Manipulations:

const variableA = jsPsych.extensions.Neurocog.getManipulation("variableA", 2);
console.log(variableA); // The value of the manipulation if specified on Gorilla, otherwise 2

Gorilla: Stimuli

⚠️ Breaking Change (as of v1.1.0): When running an experiment locally, all Stimuli must be located in a stimuli directory alongside the file initializing jsPsych. Stimuli are no longer required to be specified in the Neurocog parameters.

The key for a Stimulus must be the exact file name.

Accessing Stimuli:

const imageSrc = jsPsych.extensions.Neurocog.getStimulus('stimulus.jpg');
console.log(imageA); // 'stimuli/stimulus.jpg' locally or the path to a Gorilla Stimulus

Gorilla: Resources

⚠️ Breaking Change (as of v1.1.0): When running an experiment locally, all Resources must be located in a resources directory alongside the file initializing jsPsych. Resources are no longer required to be specified in the Neurocog parameters.

The key for a Resource must be the exact file name.

Accessing Resources:

const resourceSrc = jsPsych.extensions.Neurocog.getResource('resource.jpg');
console.log(resourceSrc); // 'resource/resource.jpg' or the path to a Gorilla Resource

State management: accessing and updating state variables

Configuring State:

const jsPsych = initJsPsych({
  // ...
  extensions: [
    {
      type: NeurocogExtension,
      params: {
        // ...
        state: {
          counter: 0,
          // ...
        },
        // ...
      }
    }
  ],
  // ...
});

The following methods can be used for interacting with the experiment state throughout the experiment:

MethodParametersDescription
getState(key)key: stringGet the value of a global state variable
setState(key, value)key: string, value: anySet the value of a global state variable

License

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

1.1.1

6 months ago

1.1.0

6 months ago

1.0.0

7 months ago

0.3.6

2 years ago

0.3.5

2 years ago

0.3.8

2 years ago

0.3.7

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.1

2 years ago