-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_figures_RT.m
185 lines (135 loc) · 5.43 KB
/
make_figures_RT.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
% collects subject RT and plots how they are distributed
% across gain and loss on average at the group level and for each subject
% Also checks overall distributions of RT for each subjects and missed
% reponses.
clear
clc
close all
% parameters to remove very fast RT <.5 secs
% will then set RT to 0 and treat them like other missed trials
rm_fast_trials = 0;
fast_trials_thres = 0.5;
rm_participants = 0; % remove paritipants excluded from quality control
machine_id = 1;
[~, code_dir] = set_dir(machine_id);
% Get which participant is in which group
participants_file = fullfile(code_dir, 'inputs', 'event_tsvs','participants.tsv');
participants = spm_load(participants_file);
group_id = strcmp(participants.group, 'equalRange');
% remove excluded subjects
if rm_participants
[participants, group_id] = ...
rm_subjects(participants, group_id, [], 1);
end
for i_group = 0:1 %loop through each group
group_idx = find(group_id==i_group); % index of each subject
if i_group == 0
gain_range = 10:2:40;
else
gain_range = 5:1:20;
end
loss_range = 5:1:20;
range(i_group+1).gain = gain_range; % to keep track of those ranges for plotting
range(i_group+1).loss = loss_range;
for i_subj = 1:numel(group_idx)
% get data for each subject
subject = participants.participant_id{ group_idx(i_subj) };
fprintf(' loading %s\n', subject)
files_2_load = spm_select('FPList', ...
fullfile(code_dir, 'inputs', 'event_tsvs'), ...
['^' subject '.*.tsv$']);
no_resp = [];
RT_mat = [];
for i_file = 1:size(files_2_load)
% load each event file
data = spm_load(files_2_load(i_file, :));
% count number of missing responses for that run
no_resp(i_file) = sum(strcmp(data.participant_response, 'NoResp')); %#ok<*SAGROW>
% initialize matrix to store results
RT_mat(:, :, i_file) = nan(numel(loss_range), numel(gain_range));
for i_trial = 1:numel(data.onset)
loss = find( loss_range==data.loss(i_trial) ); % loss index
gain = find( gain_range==data.gain(i_trial) ); % loss index
% Just a sanity check to make sure that fast trials are not
% missed trials
if strcmp(data.participant_response(i_trial), 'NoResp') ...
&& data.RT(i_trial)~=0
error('Some missed trials have an RT =/= from 0');
end
if rm_fast_trials && data.RT(i_trial) < fast_trials_thres % only include RT with plausible RT
RT_mat(loss, gain, i_file) = 0; % store RT of this trial in matrix
else
RT_mat(loss, gain, i_file) = data.RT(i_trial);
end
end
end
% store how many missed responses for that subject
participants.noresp(group_idx(i_subj),1) = sum(no_resp);
% there should be only one type of trial for each gain/loss
% combination
check_norepeat = sum(isnan(RT_mat),3);
if any(check_norepeat(:)~=3)
error('Something is off: there should be no trial type repeat.')
end
% average RT over runs
RT_mat = nanmean(RT_mat, 3);
RT_mat(RT_mat==0) = NaN; %if a trial was missed we replace its 0 value by NaN
% append to the group results
RT_mat_grp{i_group+1}(:,:,i_subj) = nanmean(RT_mat, 3);
end
end
%% plot RT
figure('name', 'RT')
CLIM = [1 2];
subplot(1, 2, 1)
imagesc( nanmean(RT_mat_grp{1},3) , CLIM )
axis square
title('RT equal indifference (seconds)')
ylabel('loss')
xlabel('gain')
set(gca, 'xtick', 1:2:numel(range(1).gain), ...
'xticklabel', range(1).gain(1:2:numel(range(1).gain)), ...
'ytick', 1:2:numel(range(1).loss), ...
'yticklabel', range(1).loss(1:2:numel(range(1).loss)))
colorbar
subplot(1, 2, 2)
imagesc( nanmean(RT_mat_grp{2},3) , CLIM )
axis square
title('RT equal range (seconds)')
ylabel('loss')
xlabel('gain')
set(gca, 'xtick', 1:2:numel(range(2).gain), ...
'xticklabel', range(2).gain(1:2:numel(range(2).gain)), ...
'ytick', 1:2:numel(range(2).loss), ...
'yticklabel', range(2).loss(1:2:numel(range(2).loss)))
colorbar
%% plot missed responses
figure('name', 'Missed responses')
bar(participants.noresp)
title('Missed responses')
ylabel('number of misses')
xlabel('subject')
%% plot RT times for each subject
figure('name', 'RT for each subject ')
subplot(1, 2, 1)
RT_to_plot = reshape(RT_mat_grp{1}, ...
[size(RT_mat_grp{1},1) * size(RT_mat_grp{1},2) , size(RT_mat_grp{1},3)]);
boxplot(RT_to_plot)
title('RT distribution per subject - equal indifference group')
ylabel('RT (secs)')
xlabel('subject')
set(gca, 'xtick', 1:2:size(RT_mat_grp{1},3), ...
'xticklabel', 1:2:size(RT_mat_grp{1},3), ...
'ytick', 0:.5:4, ...
'yticklabel', 0:.5:4)
subplot(1, 2, 2)
RT_to_plot = reshape(RT_mat_grp{2}, ...
[size(RT_mat_grp{2},1) * size(RT_mat_grp{2},2) , size(RT_mat_grp{2},3)]);
boxplot(RT_to_plot)
title('RT distribution per subject - equal range group')
ylabel('RT (secs)')
xlabel('subject')
set(gca, 'xtick', 1:2:size(RT_mat_grp{1},3), ...
'xticklabel', 1:2:size(RT_mat_grp{1},3), ...
'ytick', 0:.5:4, ...
'yticklabel', 0:.5:4)