-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconflictmonitoring_exp1_fits.m
153 lines (151 loc) · 4.99 KB
/
conflictmonitoring_exp1_fits.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
clear
clc
addpath('function')
%% conflict model 1
f = figure;
set(f,'Units','inches','position',[0,0,7,3])
expt = {'Exp. 1a','Exp. 1b'};
for exp = 1:2
switch exp
case 1
load('data/PNAS_Exp1a.mat')
case 2
load('data/PNAS_Exp1b.mat')
end
%% get mean RT
eventrials = geteventrials(data.flankerSTD);
badRTtrials = getbadRTtrials(data.sub,data.RT,0.99,0.01);
uSub = unique(data.sub);
uFV = unique(data.flankerSTD);
cong = unique(data.congruency);
index = eventrials & ~badRTtrials & data.cor ==1;
meanRT = jb_getvector(data.RT(index),data.sub(index),data.flankerSTD(index),data.congruency(index));
%% parameters
ES_weight = linspace(0,1,50);
%% model
for s = 1:length(uSub)
subRT = squeeze(meanRT(s,:,:));
for mm = 1:length(ES_weight)
w = ES_weight(mm);
for fv = 1:length(uFV)
for c = 1:length(cong)
if c == 1; fm = 45 ;end
if c == 2; fm = -45;end
eviL = abs(fm).*(fm<0).*w;
eviR = (45) .*(1-w) + (abs(fm).*(fm>0).*w);
conflict(fv,c) = eviL.*eviR;
end
end
conf = abs(conflict(:));
bc = glmfit(conf,subRT(:));
RT_c = bc(1)+conf*bc(2);
SSE_c(s,mm) = sum((RT_c-subRT(:)).^2);
end
progressbar(length(uSub),s);
end
%% find best
for s = 1:length(uSub)
bw = find(SSE_c(s,:)==min(SSE_c(s,:)));
bestweight(s)= bw(1);
end
%% best parameterisation
index = ~eventrials & ~badRTtrials & data.cor ==1;
meanRT = jb_getvector(data.RT(index),data.sub(index),data.flankerSTD(index),data.congruency(index));
RT_c = nan(length(uSub),3,2);
for s = 1:length(uSub)
subRT = squeeze(meanRT(s,:,:));
w = ES_weight(bestweight(s));
for fv = 1:length(uFV)
for c = 1:length(cong)
if c == 1; fm = 45 ;end
if c == 2; fm = -45;end
eviL = abs(fm).*(fm<0).*w;
eviR = (45) .*(1-w) + (abs(fm).*(fm>0).*w);
conflict(fv,c) = eviL.*eviR;
end
end
conf = abs(conflict(:));
bc = glmfit(conf,subRT(:));
RT_c(s,:,:) = reshape(bc(1)+conf*bc(2),[length(uFV) length(cong)]);
end
%% plot
subplot(1,2,exp);
linesem(RT_c.*1000);
title([expt{exp}]);
xticks([1 2])
xticklabels({'Cong','Incong'})
ylabel('RT(ms)')
clc;
end
suptitle('Conflict model 1');
%% conflict model 2
clear
clc
f = figure;
set(f,'Units','inches','position',[0,0,7,3])
expt = {'Exp. 1a','Exp. 1b'};
for exp = 1:2
switch exp
case 1
load('data/PNAS_Exp1a.mat')
case 2
load('data/PNAS_Exp1b.mat')
end
%% get mean RT
eventrials = geteventrials(data.flankerSTD);
badRTtrials = getbadRTtrials(data.sub,data.RT,0.99,0.01);
uSub = unique(data.sub);
index = eventrials & ~badRTtrials & data.cor ==1;
%% parameters
ES_weight = linspace(0,1,50);
%% model
for s = 1:length(uSub)
indx = find(data.sub == uSub(s) & index);
subRT = data.RT(indx);
subtm = data.targetMean(indx);
subf = data.allangles(2:end,indx);
for mm = 1:length(ES_weight)
w = ES_weight(mm);
eviL = (abs(subtm).*(subtm<0).*w) + sum((abs(subf).*(subf<0).*((1-w)./6)));
eviR = (abs(subtm).*(subtm>0).*w) + sum((abs(subf).*(subf>0).*((1-w)./6)));
conflict = eviL.*eviR;
conf = abs(conflict(:));
bc = glmfit(conf,subRT(:));
RT_c = bc(1)+conf*bc(2);
SSE_c(s,mm) = sum((RT_c-subRT(:)).^2);
end
progressbar(length(uSub),s);
end
%% find best
for s = 1:length(uSub)
bw = find(SSE_c(s,:)==min(SSE_c(s,:)));
bestweight(s)= bw(1);
end
%% best parameterisation
allmRT = [];
for s = 1:length(uSub)
indx = find(data.sub == uSub(s));
subRT = data.RT(indx);
subtm = data.targetMean(indx);
subf = data.allangles(2:end,indx);
w = ES_weight(bestweight(s));
eviL = (abs(subtm).*(subtm<0).*w) + sum((abs(subf).*(subf<0).*((1-w)./6)));
eviR = (abs(subtm).*(subtm>0).*w) + sum((abs(subf).*(subf>0).*((1-w)./6)));
conflict = eviL.*eviR;
conf = abs(conflict(:));
bc = glmfit(conf,subRT(:));
mRT = bc(1)+ bc(2)*conf;
allmRT = [allmRT;mRT];
end
%% plot
index = ~eventrials & ~badRTtrials & data.cor ==1;
RT_c = jb_getvector(allmRT(index),data.sub(index),data.flankerSTD(index),data.congruency(index)).*1000;
subplot(1,2,exp);
linesem(RT_c.*1000);
title([expt{exp}]);
xticks([1 2])
xticklabels({'Cong','Incong'})
ylabel('RT(ms)')
clc;
end
suptitle('Conflict model 2');