-
Notifications
You must be signed in to change notification settings - Fork 4
/
individual_correlation_pharma.m
190 lines (154 loc) · 7.75 KB
/
individual_correlation_pharma.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
186
187
188
189
190
function alldat = individual_correlation_pharma
% Code to fit the history-dependent drift diffusion models as described in
% Urai AE, de Gee JW, Tsetsos K, Donner TH (2019) Choice history biases subsequent evidence accumulation. eLife, in press.
%
% MIT License
% Copyright (c) Anne Urai, 2019
close all; clc;
addpath(genpath('~/code/Tools'));
global mypath colors
datasets = {'MEG'}; % CHANGE THIS TO MEG_750MS ONCE FINISHED!
% datasets = {'MEG_MEGsessions'}; % CHANGE THIS TO MEG_750MS ONCE FINISHED!
datasetnames = {{'Visual motion' '2IFC (FD) #2'}};
cnt = 1;
Gsq = 0; sz = 0;
doText = false;
% ============================================ %
% ONE LARGE PLOT WITH PANEL FOR EACH DATASET
% ============================================ %
switch sz
case 1
whichmdls = ['stimcodingsz'];
case 0
whichmdls = ['stimcoding'];
end
close all;
for d = length(datasets):-1:1
disp(datasets{d});
if Gsq,
results = readtable(sprintf('%s/summary/%s/allindividualresults_Gsq.csv', mypath, datasets{d}));
else
results = readtable(sprintf('%s/summary/%s/allindividualresults.csv', mypath, datasets{d}));
end
results = results(results.session == 0, :);
allresults = struct(); alltitles = {};
% ============================================ %
% RECODE INTO HISTORY SHIFT POINT ESTIMATES
% SEPARATELY FOR EACH PHARMA GROUP!
% ============================================ %
% color in different groups
colors1 = cbrewer('qual', 'Set2', 8);
colors2 = cbrewer('qual', 'Dark2', 8);
paired = cbrewer('qual', 'Paired', 12);
% use the stimcoding difference
results.z_prevresp_placebo = ...
results.(['z_placebo_1__' whichmdls 'dczprevresppharma']) - results.(['z_placebo_2__' whichmdls 'dczprevresppharma']);
results.v_prevresp_placebo = ...
results.(['dc_placebo_1__' whichmdls 'dczprevresppharma']) - results.(['dc_placebo_2__' whichmdls 'dczprevresppharma']);
allresults(1).z_prevresp = results.z_prevresp_placebo;
allresults(1).v_prevresp = results.v_prevresp_placebo;
allresults(1).criterionshift = results.repetition;
alltitles{1} = {cat(2, datasetnames{1}{1}, ' ', datasetnames{1}{2}) ' - Placebo'};
alltitles{1} = {'Placebo'};
allresults(1).scattercolor = colors1(8, :);
allresults(1).meancolor = colors2(8, :);
allresults(1).marker = 'o';
% ATOMOXETINE
results.z_prevresp_atomoxetine = ...
results.(['z_atomoxetine_1__' whichmdls 'dczprevresppharma']) - results.(['z_atomoxetine_2__' whichmdls 'dczprevresppharma']);
results.v_prevresp_atomoxetine = ...
results.(['dc_atomoxetine_1__' whichmdls 'dczprevresppharma']) - results.(['dc_atomoxetine_2__' whichmdls 'dczprevresppharma']);
allresults(2).z_prevresp = results.z_prevresp_atomoxetine;
allresults(2).v_prevresp = results.v_prevresp_atomoxetine;
allresults(2).criterionshift = results.repetition;
alltitles{2} = {cat(2, datasetnames{1}{1}, ' ', datasetnames{1}{2}) ' - Atomoxetine'};
alltitles{2} = {'Atomoxetine'};
allresults(2).scattercolor = paired(5, :);
allresults(2).meancolor = paired(6, :);
allresults(2).marker = 's';
% DONEPEZIL
results.z_prevresp_donepezil = ...
results.(['z_donepezil_1__' whichmdls 'dczprevresppharma']) - results.(['z_donepezil_2__' whichmdls 'dczprevresppharma']);
results.v_prevresp_donepezil = ...
results.(['dc_donepezil_1__' whichmdls 'dczprevresppharma']) - results.(['dc_donepezil_2__' whichmdls 'dczprevresppharma']);
allresults(3).z_prevresp = results.z_prevresp_donepezil;
allresults(3).v_prevresp = results.v_prevresp_donepezil;
allresults(3).criterionshift = results.repetition;
alltitles{3} = {cat(2, datasetnames{1}{1}, ' ', datasetnames{1}{2}) ' - Donepezil'};
alltitles{3} = {'Donepezil'};
allresults(3).scattercolor = paired(1, :);
allresults(3).meancolor = paired(2, :);
allresults(3).marker = 'd';
disp(datasets{d}); disp(numel(unique(results.subjnr)));
close all;
% PLOT
sp1 = subplot(4,4,1); hold on;
[rho1, tt1] = plotScatter(allresults, 'z_prevresp', 0.585, doText);
ylabel('P(repeat)');
sp2 = subplot(4,4,2); hold on;
[rho2, tt2, handles] = plotScatter(allresults, 'v_prevresp', 0.05, doText);
set(gca, 'yticklabel', []);
set(sp2, 'ylim', get(sp1, 'ylim'), 'ytick', get(sp1, 'ytick'));
% compute the difference in correlation
[rho3, pval3] = corr(cat(1, allresults(:).v_prevresp), cat(1, allresults(:).z_prevresp), ...
'rows', 'complete', 'type', 'pearson');
if pval3 < 0.05,
fprintf('warning %s: rho = %.3f, pval = %.3f \n', datasets{d}, rho3, pval3);
end
[rhodiff, ~, pval] = rddiffci(rho1,rho2,rho3,numel(~isnan( cat(1, allresults(:).criterionshift))), 0.05);
% move together
sp2.Position(1) = sp2.Position(1) - 0.08;
ss = suplabel('Visual motion 2IFC (FD) #2', 't');
set(ss, 'fontweight', 'normal');
ss.FontWeight = 'normal';
ss.Position(2) = ss.Position(2) - 0.03;
% add colored axes after suplabel (which makes them black)
xlabel(sp1, 'History shift in z');
set(sp1, 'xcolor', colors(1, :));
xlabel(sp2, 'History shift in v_{bias}');
set(sp2, 'xcolor', colors(2, :));
if doText,
%% add line between the two correlation coefficients
txt = {sprintf('\\Deltar(%d) = %.3f, p = %.3f', length(find(~isnan(cat(1, allresults(:).criterionshift) )))-3, rhodiff, pval)};
if pval < 0.001,
txt = {sprintf('\\Deltar(%d) = %.3f, p < 0.001', length(find(~isnan(cat(1, allresults(:).criterionshift) )))-3, rhodiff)};
end
%title(txt, 'fontweight', 'normal', 'fontsize', 6, 'horizontalalignment', 'left');
end
tightfig;
if Gsq,
print(gcf, '-dpdf', sprintf('~/Data/serialHDDM/figure1c_Gsq_modelfree_pharma_sz%d_d%d.pdf', d, sz));
else
print(gcf, '-dpdf', sprintf('~/Data/serialHDDM/figure1c_HDDM_modelfree_pharma_sz%d_d%d.pdf', d, sz));
%print(gcf, '-depsc', sprintf('~/Data/serialHDDM/figure1c_HDDM_modelfree_stimcoding_d%d.eps', d));
end
for a = 1:length(allresults),
% SAVE CORRELATIONS FOR OVERVIEW PLOT
[r,p,rlo,rup] = corrcoef(allresults(a).z_prevresp, allresults(a).criterionshift, 'rows', 'complete');
alldat(cnt).corrz = r(1,2);
alldat(cnt).corrz_ci = [rlo(1,2) rup(1,2)];
alldat(cnt).pz = p(1,2);
alldat(cnt).bfz = corrbf(r(1,2), numel(allresults(a).z_prevresp));
[r,p,rlo,rup] = corrcoef(allresults(a).v_prevresp, allresults(a).criterionshift, 'rows', 'complete');
alldat(cnt).corrv = r(1,2);
alldat(cnt).corrv_ci = [rlo(1,2) rup(1,2)];
alldat(cnt).pv = p(1,2);
alldat(cnt).bfv = corrbf(r(1,2), numel(allresults(a).v_prevresp));
alldat(cnt).datasets = datasets{d};
alldat(cnt).datasetnames = alltitles{a};
% also add the difference in r, Steigers test
[r,p,rlo,rup] = corrcoef(allresults(a).v_prevresp, allresults(a).z_prevresp, 'rows', 'complete');
[rhodiff, rhodiffci, pval] = rddiffci(alldat(cnt).corrz,alldat(cnt).corrv, ...
r(1,2), numel(allresults(a).v_prevresp), 0.05);
alldat(cnt).corrdiff = rhodiff;
alldat(cnt).corrdiff_ci = rhodiffci;
alldat(cnt).pdiff = pval;
% some layout things
alldat(cnt).meancolor = allresults(a).meancolor;
alldat(cnt).scattercolor = allresults(a).scattercolor;
alldat(cnt).marker = allresults(a).marker;
cnt = cnt + 1;
end
end
end