-
-
Save susanBuck/a690d543254fe24c96b43174239d368f to your computer and use it in GitHub Desktop.
est-conditions.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Modify the following words array with your own words | |
// There should be 10 words per block, with the exception of neutral where you should have double (20) | |
// In our example, emotionA is "calm" and emotionB is "scary" | |
let words = { | |
practice: ['knots', 'muddy', 'minor', 'short', 'tread', 'table', 'plant', 'river', 'board', 'glass'], | |
neutral: ['crumb', 'snail', 'throw', 'arrow', 'ledge', 'plain', 'short', 'marsh', 'block', 'scale', 'wheel', 'chair', 'drink', 'shelf', 'wheel', 'paper', 'stick', 'plate', 'score', 'point'], | |
emotionA: ['peace', 'relax', 'bathe', 'ocean', 'breeze', 'quiet', 'dream', 'cloud', 'float', 'haven'], | |
emotionB: ['ghost', 'bones', 'creep', 'blood', 'storm', 'eerie', 'grave', 'beast', 'blade', 'fangs'], | |
}; | |
// Your final experiment should show 36 words per block | |
// when developing your experiment you can reduce this number | |
// to expedite the process of testing the experiment | |
let count = 4; | |
// The following code will process the above information into a `conditions` array you | |
// can use to structure your experiment. | |
// | |
// !! DO NOT MODIFY ANY OF THE FOLLOWING CODE !! | |
// | |
let conditions = generateConditions(); | |
console.log(conditions); | |
function generateConditions() { | |
// jsPsych is needed for randomization functionality | |
let jsPsych = initJsPsych(); | |
// Initialize our empty array of conditions | |
let conditions = []; | |
// Create an array of blocks where 'practice' is always first, followed by 'emotionA' and 'emotionB' in random order | |
let blocks = ['practice'].concat(shuffle(['emotionA', 'emotionB'])); | |
// Calculate how many neutral words we’ll need | |
// count = number of trials needed | |
// we divide this in half because we only need half neutral words in each block | |
// and we multiple it by 3 because there are three blocks (practice, emotionA, emotionB) | |
let wordsNeeded = (count / 2) * 3; | |
// Create a shuffled pool of neutral words with enough words to cover all trials | |
repeat = Math.ceil(wordsNeeded / words['neutral'].length); | |
let neutralWords = jsPsych.randomization.repeat(words['neutral'], repeat); | |
// Create a shuffled pool of colors with enough colors to cover all trials | |
// Note: Not using shuffleNoRepeats colors because it is okay to have repeat colors in a row | |
let colors = ['red', 'green', 'blue']; | |
repeat = Math.ceil(count / colors.length * 3); | |
colors = jsPsych.randomization.repeat(colors, repeat); | |
// Loop through our blocks, generating trial data | |
for (let block of blocks) { | |
// Create a shuffled pool of emotion words with enough words to cover all trials | |
repeat = Math.ceil((count / 2) / words[block].length); | |
let emotionWords = jsPsych.randomization.repeat(words[block], repeat); | |
emotionWords = emotionWords.splice(0, count / 2); | |
// Take a splice of neutral words and join them with the emotion words | |
let theseNeutralWords = neutralWords.splice(0, count / 2); | |
let wordPool = theseNeutralWords.concat(emotionWords); | |
// Shuffle the word pool using shuffleNoRepeats which makes sure we don't get two of the same words in a row | |
wordPool = jsPsych.randomization.shuffleNoRepeats(wordPool); | |
// Generate trials | |
let trials = []; | |
for (let i = 0; i < count; i++) { | |
let word = wordPool[i]; | |
let color = colors.pop(); | |
trials.push({ | |
word: word, | |
valence: getValence(word), | |
color: color, | |
expectedResponse: color[0] | |
}) | |
} | |
// Push to conditions | |
conditions.push({ | |
block: block, | |
trials: shuffle(trials), | |
}); | |
} | |
return conditions; | |
} | |
/** | |
* The following are miscellaneous array functions utilized in the above code | |
*/ | |
// Utility function to shuffle an array | |
function shuffle(array) { | |
for (let i = array.length - 1; i > 0; i--) { | |
const j = Math.floor(Math.random() * (i + 1)); | |
[array[i], array[j]] = [array[j], array[i]]; | |
} | |
return array; | |
} | |
// Utility function to get the valence of a word | |
function getValence(word) { | |
if (words['practice'].includes(word) || words['neutral'].includes(word)) { | |
return 'neutral'; | |
} else if (words['emotionA'].includes(word)) { | |
return 'emotionA'; | |
} else { | |
return 'emotionB'; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"block": "practice", | |
"trials": [ | |
{ | |
"word": "paper", | |
"valence": "neutral", | |
"color": "red", | |
"expectedResponse": "r" | |
}, | |
{ | |
"word": "tread", | |
"valence": "neutral", | |
"color": "green", | |
"expectedResponse": "g" | |
}, | |
{ | |
"word": "knots", | |
"valence": "neutral", | |
"color": "red", | |
"expectedResponse": "r" | |
}, | |
{ | |
"word": "short", | |
"valence": "neutral", | |
"color": "red", | |
"expectedResponse": "r" | |
}, | |
{ | |
"word": "plate", | |
"valence": "neutral", | |
"color": "blue", | |
"expectedResponse": "b" | |
}, | |
{ | |
"word": "crumb", | |
"valence": "neutral", | |
"color": "green", | |
"expectedResponse": "g" | |
}, | |
{ | |
"word": "chair", | |
"valence": "neutral", | |
"color": "green", | |
"expectedResponse": "g" | |
}, | |
{ | |
"word": "short", | |
"valence": "neutral", | |
"color": "blue", | |
"expectedResponse": "b" | |
}, | |
{ | |
"word": "plant", | |
"valence": "neutral", | |
"color": "blue", | |
"expectedResponse": "b" | |
}, | |
{ | |
"word": "shelf", | |
"valence": "neutral", | |
"color": "green", | |
"expectedResponse": "g" | |
}, | |
{ | |
"word": "table", | |
"valence": "neutral", | |
"color": "red", | |
"expectedResponse": "r" | |
}, | |
{ | |
"word": "minor", | |
"valence": "neutral", | |
"color": "blue", | |
"expectedResponse": "b" | |
}, | |
{ | |
"word": "marsh", | |
"valence": "neutral", | |
"color": "blue", | |
"expectedResponse": "b" | |
}, | |
{ | |
"word": "glass", | |
"valence": "neutral", | |
"color": "blue", | |
"expectedResponse": "b" | |
}, | |
{ | |
"word": "short", | |
"valence": "neutral", | |
"color": "red", | |
"expectedResponse": "r" | |
}, | |
{ | |
"word": "river", | |
"valence": "neutral", | |
"color": "red", | |
"expectedResponse": "r" | |
}, | |
{ | |
"word": "throw", | |
"valence": "neutral", | |
"color": "blue", | |
"expectedResponse": "b" | |
}, | |
{ | |
"word": "plain", | |
"valence": "neutral", | |
"color": "red", | |
"expectedResponse": "r" | |
}, | |
{ | |
"word": "plain", | |
"valence": "neutral", | |
"color": "red", | |
"expectedResponse": "r" | |
}, | |
{ | |
"word": "plant", | |
"valence": "neutral", | |
"color": "red", | |
"expectedResponse": "r" | |
}, | |
{ | |
"word": "river", | |
"valence": "neutral", | |
"color": "red", | |
"expectedResponse": "r" | |
}, | |
{ | |
"word": "board", | |
"valence": "neutral", | |
"color": "blue", | |
"expectedResponse": "b" | |
}, | |
{ | |
"word": "arrow", | |
"valence": "neutral", | |
"color": "green", | |
"expectedResponse": "g" | |
}, | |
{ | |
"word": "drink", | |
"valence": "neutral", | |
"color": "blue", | |
"expectedResponse": "b" | |
}, | |
{ | |
"word": "score", | |
"valence": "neutral", | |
"color": "blue", | |
"expectedResponse": "b" | |
}, | |
{ | |
"word": "tread", | |
"valence": "neutral", | |
"color": "red", | |
"expectedResponse": "r" | |
}, | |
{ | |
"word": "plate", | |
"valence": "neutral", | |
"color": "blue", | |
"expectedResponse": "b" | |
}, | |
{ | |
"word": "glass", | |
"valence": "neutral", | |
"color": "green", | |
"expectedResponse": "g" | |
}, | |
{ | |
"word": "drink", | |
"valence": "neutral", | |
"color": "green", | |
"expectedResponse": "g" | |
}, | |
{ | |
"word": "muddy", | |
"valence": "neutral", | |
"color": "green", | |
"expectedResponse": "g" | |
}, | |
{ | |
"word": "point", | |
"valence": "neutral", | |
"color": "blue", | |
"expectedResponse": "b" | |
}, | |
{ | |
"word": "knots", | |
"valence": "neutral", | |
"color": "green", | |
"expectedResponse": "g" | |
}, | |
{ | |
"word": "board", | |
"valence": "neutral", | |
"color": "blue", | |
"expectedResponse": "b" | |
}, | |
{ | |
"word": "marsh", | |
"valence": "neutral", | |
"color": "blue", | |
"expectedResponse": "b" | |
}, | |
{ | |
"word": "chair", | |
"valence": "neutral", | |
"color": "green", | |
"expectedResponse": "g" | |
}, | |
{ | |
"word": "minor", | |
"valence": "neutral", | |
"color": "blue", | |
"expectedResponse": "b" | |
} | |
] | |
}, | |
{ | |
"block": "emotionB", | |
"trials": [ | |
{ | |
"word": "blade", | |
"valence": "emotionB", | |
"color": "green", | |
"expectedResponse": "g" | |
}, | |
{ | |
"word": "grave", | |
"valence": "emotionB", | |
"color": "red", | |
"expectedResponse": "r" | |
}, | |
{ | |
"word": "beast", | |
"valence": "emotionB", | |
"color": "red", | |
"expectedResponse": "r" | |
}, | |
{ | |
"word": "ghost", | |
"valence": "emotionB", | |
"color": "green", | |
"expectedResponse": "g" | |
}, | |
{ | |
"word": "eerie", | |
"valence": "emotionB", | |
"color": "red", | |
"expectedResponse": "r" | |
}, | |
{ | |
"word": "point", | |
"valence": "neutral", | |
"color": "green", | |
"expectedResponse": "g" | |
}, | |
{ | |
"word": "storm", | |
"valence": "emotionB", | |
"color": "red", | |
"expectedResponse": "r" | |
}, | |
{ | |
"word": "snail", | |
"valence": "neutral", | |
"color": "blue", | |
"expectedResponse": "b" | |
}, | |
{ | |
"word": "wheel", | |
"valence": "neutral", | |
"color": "blue", | |
"expectedResponse": "b" | |
}, | |
{ | |
"word": "wheel", | |
"valence": "neutral", | |
"color": "red", | |
"expectedResponse": "r" | |
}, | |
{ | |
"word": "arrow", | |
"valence": "neutral", | |
"color": "red", | |
"expectedResponse": "r" | |
}, | |
{ | |
"word": "score", | |
"valence": "neutral", | |
"color": "green", | |
"expectedResponse": "g" | |
}, | |
{ | |
"word": "short", | |
"valence": "neutral", | |
"color": "blue", | |
"expectedResponse": "b" | |
}, | |
{ | |
"word": "wheel", | |
"valence": "neutral", | |
"color": "red", | |
"expectedResponse": "r" | |
}, | |
{ | |
"word": "stick", | |
"valence": "neutral", | |
"color": "green", | |
"expectedResponse": "g" | |
}, | |
{ | |
"word": "blade", | |
"valence": "emotionB", | |
"color": "blue", | |
"expectedResponse": "b" | |
}, | |
{ | |
"word": "block", | |
"valence": "neutral", | |
"color": "blue", | |
"expectedResponse": "b" | |
}, | |
{ | |
"word": "plain", | |
"valence": "neutral", | |
"color": "red", | |
"expectedResponse": "r" | |
}, | |
{ | |
"word": "bones", | |
"valence": "emotionB", | |
"color": "blue", | |
"expectedResponse": "b" | |
}, | |
{ | |
"word": "scale", | |
"valence": "neutral", | |
"color": "red", | |
"expectedResponse": "r" | |
}, | |
{ | |
"word": "shelf", | |
"valence": "neutral", | |
"color": "blue", | |
"expectedResponse": "b" | |
}, | |
{ | |
"word": "eerie", | |
"valence": "emotionB", | |
"color": "red", | |
"expectedResponse": "r" | |
}, | |
{ | |
"word": "ghost", | |
"valence": "emotionB", | |
"color": "green", | |
"expectedResponse": "g" | |
}, | |
{ | |
"word": "creep", | |
"valence": "emotionB", | |
"color": "blue", | |
"expectedResponse": "b" | |
}, | |
{ | |
"word": "snail", | |
"valence": "neutral", | |
"color": "green", | |
"expectedResponse": "g" | |
}, | |
{ | |
"word": "storm", | |
"valence": "emotionB", | |
"color": "blue", | |
"expectedResponse": "b" | |
}, | |
{ | |
"word": "blood", | |
"valence": "emotionB", | |
"color": "green", | |
"expectedResponse": "g" | |
}, | |
{ | |
"word": "grave", | |
"valence": "emotionB", | |
"color": "red", | |
"expectedResponse": "r" | |
}, | |
{ | |
"word": "fangs", | |
"valence": "emotionB", | |
"color": "red", | |
"expectedResponse": "r" | |
}, | |
{ | |
"word": "creep", | |
"valence": "emotionB", | |
"color": "red", | |
"expectedResponse": "r" | |
}, | |
{ | |
"word": "ledge", | |
"valence": "neutral", | |
"color": "red", | |
"expectedResponse": "r" | |
}, | |
{ | |
"word": "point", | |
"valence": "neutral", | |
"color": "blue", | |
"expectedResponse": "b" | |
}, | |
{ | |
"word": "block", | |
"valence": "neutral", | |
"color": "blue", | |
"expectedResponse": "b" | |
}, | |
{ | |
"word": "blood", | |
"valence": "emotionB", | |
"color": "green", | |
"expectedResponse": "g" | |
}, | |
{ | |
"word": "throw", | |
"valence": "neutral", | |
"color": "red", | |
"expectedResponse": "r" | |
}, | |
{ | |
"word": "beast", | |
"valence": "emotionB", | |
"color": "blue", | |
"expectedResponse": "b" | |
} | |
] | |
}, | |
{ | |
"block": "emotionA", | |
"trials": [ | |
{ | |
"word": "shelf", | |
"valence": "neutral", | |
"color": "red", | |
"expectedResponse": "r" | |
}, | |
{ | |
"word": "score", | |
"valence": "neutral", | |
"color": "blue", | |
"expectedResponse": "b" | |
}, | |
{ | |
"word": "short", | |
"valence": "neutral", | |
"color": "blue", | |
"expectedResponse": "b" | |
}, | |
{ | |
"word": "cloud", | |
"valence": "emotionA", | |
"color": "green", | |
"expectedResponse": "g" | |
}, | |
{ | |
"word": "block", | |
"valence": "neutral", | |
"color": "green", | |
"expectedResponse": "g" | |
}, | |
{ | |
"word": "quiet", | |
"valence": "emotionA", | |
"color": "green", | |
"expectedResponse": "g" | |
}, | |
{ | |
"word": "dream", | |
"valence": "emotionA", | |
"color": "green", | |
"expectedResponse": "g" | |
}, | |
{ | |
"word": "chair", | |
"valence": "neutral", | |
"color": "red", | |
"expectedResponse": "r" | |
}, | |
{ | |
"word": "arrow", | |
"valence": "neutral", | |
"color": "green", | |
"expectedResponse": "g" | |
}, | |
{ | |
"word": "relax", | |
"valence": "emotionA", | |
"color": "blue", | |
"expectedResponse": "b" | |
}, | |
{ | |
"word": "dream", | |
"valence": "emotionA", | |
"color": "green", | |
"expectedResponse": "g" | |
}, | |
{ | |
"word": "paper", | |
"valence": "neutral", | |
"color": "green", | |
"expectedResponse": "g" | |
}, | |
{ | |
"word": "crumb", | |
"valence": "neutral", | |
"color": "green", | |
"expectedResponse": "g" | |
}, | |
{ | |
"word": "breeze", | |
"valence": "emotionA", | |
"color": "red", | |
"expectedResponse": "r" | |
}, | |
{ | |
"word": "breeze", | |
"valence": "emotionA", | |
"color": "red", | |
"expectedResponse": "r" | |
}, | |
{ | |
"word": "bathe", | |
"valence": "emotionA", | |
"color": "green", | |
"expectedResponse": "g" | |
}, | |
{ | |
"word": "wheel", | |
"valence": "neutral", | |
"color": "green", | |
"expectedResponse": "g" | |
}, | |
{ | |
"word": "float", | |
"valence": "emotionA", | |
"color": "red", | |
"expectedResponse": "r" | |
}, | |
{ | |
"word": "ocean", | |
"valence": "emotionA", | |
"color": "red", | |
"expectedResponse": "r" | |
}, | |
{ | |
"word": "marsh", | |
"valence": "neutral", | |
"color": "blue", | |
"expectedResponse": "b" | |
}, | |
{ | |
"word": "wheel", | |
"valence": "neutral", | |
"color": "green", | |
"expectedResponse": "g" | |
}, | |
{ | |
"word": "cloud", | |
"valence": "emotionA", | |
"color": "blue", | |
"expectedResponse": "b" | |
}, | |
{ | |
"word": "scale", | |
"valence": "neutral", | |
"color": "blue", | |
"expectedResponse": "b" | |
}, | |
{ | |
"word": "ledge", | |
"valence": "neutral", | |
"color": "blue", | |
"expectedResponse": "b" | |
}, | |
{ | |
"word": "stick", | |
"valence": "neutral", | |
"color": "red", | |
"expectedResponse": "r" | |
}, | |
{ | |
"word": "stick", | |
"valence": "neutral", | |
"color": "green", | |
"expectedResponse": "g" | |
}, | |
{ | |
"word": "ocean", | |
"valence": "emotionA", | |
"color": "blue", | |
"expectedResponse": "b" | |
}, | |
{ | |
"word": "quiet", | |
"valence": "emotionA", | |
"color": "red", | |
"expectedResponse": "r" | |
}, | |
{ | |
"word": "peace", | |
"valence": "emotionA", | |
"color": "blue", | |
"expectedResponse": "b" | |
}, | |
{ | |
"word": "haven", | |
"valence": "emotionA", | |
"color": "red", | |
"expectedResponse": "r" | |
}, | |
{ | |
"word": "plate", | |
"valence": "neutral", | |
"color": "green", | |
"expectedResponse": "g" | |
}, | |
{ | |
"word": "float", | |
"valence": "emotionA", | |
"color": "green", | |
"expectedResponse": "g" | |
}, | |
{ | |
"word": "peace", | |
"valence": "emotionA", | |
"color": "green", | |
"expectedResponse": "g" | |
}, | |
{ | |
"word": "bathe", | |
"valence": "emotionA", | |
"color": "green", | |
"expectedResponse": "g" | |
}, | |
{ | |
"word": "paper", | |
"valence": "neutral", | |
"color": "red", | |
"expectedResponse": "r" | |
}, | |
{ | |
"word": "scale", | |
"valence": "neutral", | |
"color": "green", | |
"expectedResponse": "g" | |
} | |
] | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment