Skip to content

Commit e80fadf

Browse files
committed
Merge pull request #338 from IanEisenberg/titrate
updated discount tirate
2 parents fd1674c + 611a10b commit e80fadf

File tree

2 files changed

+54
-7
lines changed

2 files changed

+54
-7
lines changed

discount_titrate/config.json

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626
"time":10,
2727
"reference": "http://www.nature.com/neuro/journal/v13/n5/extref/nn.2516-S1.pdf",
2828
"publish":"True",
29+
"experiment_variables": [{
30+
"name":"credit_var",
31+
"type":"credit",
32+
"datatype": "boolean",
33+
"description":"True if avg_rt > 200"
34+
}],
2935
"deployment_variables":{"jspsych_init":
3036
{"fullscreen": true,
3137
"display_element": "getDisplayElement",

discount_titrate/experiment.js

+48-7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,47 @@ function addID() {
2727
})
2828
}
2929

30+
function assessPerformance() {
31+
/* Function to calculate the "credit_var", which is a boolean used to
32+
credit individual experiments in expfactory. */
33+
var experiment_data = jsPsych.data.getTrialsOfType('poldrack-single-stim')
34+
var missed_count = 0
35+
var trial_count = 0
36+
var rt_array = []
37+
var rt = 0
38+
//record choices participants made
39+
var choice_counts = {}
40+
choice_counts[-1] = 0
41+
for (var k = 0; k < choices.length; k++) {
42+
choice_counts[choices[k]] = 0
43+
}
44+
for (var i = 0; i < experiment_data.length; i++) {
45+
trial_count += 1
46+
rt = experiment_data[i].rt
47+
key = experiment_data[i].key_press
48+
choice_counts[key] += 1
49+
if (rt == -1) {
50+
missed_count += 1
51+
} else {
52+
rt_array.push(rt)
53+
}
54+
}
55+
//calculate average rt
56+
var sum = 0
57+
for (var j = 0; j < rt_array.length; j++) {
58+
sum += rt_array[j]
59+
}
60+
var avg_rt = sum / rt_array.length
61+
//calculate whether response distribution is okay
62+
var responses_ok = true
63+
Object.keys(choice_counts).forEach(function(key, index) {
64+
if (choice_counts[key] > trial_count * 0.85) {
65+
responses_ok = false
66+
}
67+
})
68+
credit_var = (avg_rt > 200) && responses_ok
69+
}
70+
3071
var getInstructFeedback = function() {
3172
return '<div class = centerbox><p class = center-block-text>' + feedback_instruct_text +
3273
'</p></div>'
@@ -83,8 +124,10 @@ var run_attention_checks = false
83124
var attention_check_thresh = 0.65
84125
var sumInstructTime = 0 //ms
85126
var instructTimeThresh = 0 ///in seconds
127+
var credit_var = true
86128

87129
// task specific variables
130+
var choices = [80, 81]
88131
//First generate smaller amounts (mean = 20, sd = 10, clipped at 5 and 40)
89132
var small_amts = [];
90133
for (i = 0; i < 36; i++) {
@@ -178,7 +221,6 @@ var feedback_instruct_block = {
178221
timing_response: 180000
179222
};
180223
/// This ensures that the subject does not read through the instructions too quickly. If they do it too quickly, then we will go over the loop again.
181-
var instruction_trials = []
182224
var instructions_block = {
183225
type: 'poldrack-instructions',
184226
data: {
@@ -191,11 +233,9 @@ var instructions_block = {
191233
show_clickable_nav: true,
192234
timing_post_trial: 1000
193235
};
194-
instruction_trials.push(feedback_instruct_block)
195-
instruction_trials.push(instructions_block)
196236

197237
var instruction_node = {
198-
timeline: instruction_trials,
238+
timeline: [feedback_instruct_block, instructions_block],
199239
/* This function defines stopping criteria */
200240
loop_function: function(data) {
201241
for (var i = 0; i < data.length; i++) {
@@ -241,7 +281,7 @@ var practice_block = {
241281
"<div class = centerbox id='container'><p class = center-block-text>Please select the option that you would prefer pressing <strong>'q'</strong> for left <strong>'p'</strong> for right:</p><div class='table'><div class='row'><div id = 'option'><center><font color='green'>$20.58<br>today</font></center></div><div id = 'option'><center><font color='green'>$25.93<br>2 weeks</font></center></div></div></div></div>"
242282
],
243283
is_html: true,
244-
choices: [80, 81],
284+
choices: choices,
245285
response_ends_trial: true,
246286
on_finish: function(data) {
247287
whichKey = data.key_press
@@ -275,7 +315,7 @@ var test_block = {
275315
type: 'poldrack-single-stim',
276316
timeline: trials,
277317
is_html: true,
278-
choices: [80, 81],
318+
choices: choices,
279319
randomize_order: true,
280320
response_ends_trial: true,
281321
on_finish: function(data) {
@@ -303,7 +343,8 @@ var end_block = {
303343
},
304344
text: '<div class = centerbox><p class = center-block-text>Thanks for completing this task!</p><p class = center-block-text>Press <strong>enter</strong> to continue.</p></div>',
305345
cont_key: [13],
306-
timing_post_trial: 0
346+
timing_post_trial: 0,
347+
on_finish: assessPerformance
307348
};
308349

309350

0 commit comments

Comments
 (0)