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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219 | %% Dynamics of Pavlovian and adaptation effects (regression analysis)- Simulation and Data- Fig. 5
clear;close all;clc;
addpath('../DataAnalysis')
%% load data
load data_diffCond
load Differential;
diff_cond.ha=Differential.timeCourse_indiv_org;
[nsubs,ntrials] = size(diff_cond.ha);
nlearning = 600; % learning trials
nprobe = ntrials-nlearning; % washout
load('RW_sim_ha') % From the following simulation code: rw_sim_diff_csScheduleOfExp1.m
sim_ha_RW=V;
load('SS_sim_ha') % From the following simulation code: ss_sim_diff_csScheduleOfExp1.m)
sim_ha_SS=x;
%%%%%%%%%%%%%%%%%%%%%
%% RESCORLA-WAGNER %%
%%%%%%%%%%%%%%%%%%%%%
block_l = 50; % trials per phase
Ps = 1:block_l:600+block_l; % lerning blocks
Ps_w = 601:block_l:ntrials+block_l; % testing blocks
Ps_w(end) = 800;
for j = 1:nsubs
ha = [nan diff(diff_cond.ha(j,1:end))]; % we're just fitting on learning
us = diff_cond.cs_p(j,1:end); % cs schedule
X_learn = [zscore(us(1:600))' zscore(us(2:601))' zscore(us(1:600))'.*zscore(us(2:601))'];
B_learn(j,:) = regress(ha(2:601)',[X_learn ones(600,1)]);
X_test = [zscore(us(600:799))' zscore(us(601:800))' zscore(us(600:799))'.*zscore(us(601:800))'];
B_test(j,:) = regress(ha(601:800)',[X_test ones(200,1)]);
%%%%%%%%%%%%%%%%%%%%%%%%
%% now do it by phase %%
%%%%%%%%%%%%%%%%%%%%%%%%
%% DATA %%
% learning
for k = 1:nlearning/block_l
X = [us(Ps(k):Ps(k+1)-1)' us(Ps(k)+1:Ps(k+1))' us(Ps(k):Ps(k+1)-1)'.*us(Ps(k)+1:Ps(k+1))'];
hatmp = ha(Ps(k)+1:Ps(k+1));
tmp = regress(hatmp',[X ones(block_l,1)]);
Bs_prev(j,k) = tmp(1);
Bs_cur(j,k) = tmp(2);
end
% testing/washout
for k = 1:nprobe/block_l
X = [us(Ps_w(k)+1:Ps_w(k+1))']; % only pavlovian
hatmp = ha(Ps_w(k)+1:Ps_w(k+1));
bl = block_l;
if k == nprobe/block_l
bl = block_l-1;
end
tmp = regress(hatmp',[X ones(bl,1)]);
Bs_cur_w(j,k) = tmp(1);
end
%% SIMS %%
% RW
ha_sim_RW = [nan diff(sim_ha_RW(j,:))];
% learning
for k = 1:nlearning/block_l
X = [us(Ps(k):Ps(k+1)-1)' us(Ps(k)+1:Ps(k+1))' us(Ps(k):Ps(k+1)-1)'.*us(Ps(k)+1:Ps(k+1))'];
hatmp = ha_sim_RW(Ps(k)+1:Ps(k+1));
tmp = regress(hatmp',[X ones(block_l,1)]);
Bs_prev_sim_RW(j,k) = tmp(1);
Bs_cur_sim_RW(j,k) = tmp(2);
end
% testing/washout
for k = 1:nprobe/block_l
X = [us(Ps_w(k)+1:Ps_w(k+1))'];
hatmp = ha_sim_RW(Ps_w(k)+1:Ps_w(k+1));
bl = block_l;
if k == nprobe/block_l
bl = block_l-1;
end
tmp = regress(hatmp',[X ones(bl,1)]);
Bs_cur_sim_w_RW(j,k) = tmp(1);
end
% SS
ha_sim_SS = [nan diff(sim_ha_SS(j,:))];
% learning
for k = 1:nlearning/block_l
X = [us(Ps(k):Ps(k+1)-1)' us(Ps(k)+1:Ps(k+1))' us(Ps(k):Ps(k+1)-1)'.*us(Ps(k)+1:Ps(k+1))'];
hatmp = ha_sim_SS(Ps(k)+1:Ps(k+1));
tmp = regress(hatmp',[X ones(block_l,1)]);
Bs_prev_sim_SS(j,k) = tmp(1);
Bs_cur_sim_SS(j,k) = tmp(2);
end
% testing/washout
for k = 1:nprobe/block_l
X = [us(Ps_w(k):Ps_w(k+1)-1)' us(Ps_w(k)+1:Ps_w(k+1))' us(Ps_w(k):Ps_w(k+1)-1)'.*us(Ps_w(k)+1:Ps_w(k+1))'];
hatmp = ha_sim_SS(Ps_w(k)+1:Ps_w(k+1));
bl = block_l;
if k == nprobe/block_l
bl = block_l-1;
end
tmp = regress(hatmp',[X ones(bl,1)]);
Bs_prev_sim_w_SS(j,k) = tmp(1);
Bs_cur_sim_w_SS(j,k) = tmp(2);
end
end
%% Plot Data
afs=24;
tfs=18;
ms=10;
xLim=[0.8 12.2];
yLim=[-0.5 4.5];
co = [[1 1 1]*180;97 129 158]/255;
co_indiv = [[1 1 1]*200;121,161,197]/255;
lw = 1;
figSize=[50 100 450 400];
bins=1:nlearning/block_l;
figure('position',figSize);
hold on
for p=1:2
if p==1
Bs=Bs_prev;
else
Bs=Bs_cur;
end
mBs=nanmean(Bs);
seBs=nanstd(Bs)/sqrt(nsubs);
varBs=[mBs-seBs;mBs+seBs];
fill([bins flip(bins)],[varBs(1,bins) flip(varBs(2,bins))]',co(p,:),'linestyle','none','facealpha',0.3);
plot(bins,mBs,'o','markerfacecolor',co(p,:),'markeredgecolor',co(p,:),'markersize',ms,'linewidth',lw);
end
h=lsline;
h(1).Color=.9*co(2,:);
h(2).Color=.9*co(1,:);
h(1).LineWidth=5;
h(2).LineWidth=5;
xlim(xLim)
ylim(yLim)
xlabel('Bin (50 trials)','fontsize',afs);
ylabel('Regression \beta','fontsize',afs);
set(gca,'xtick',2:2:12,'ytick',0:1:4,'fontsize',tfs);
box off;
% organize data for linear mixed model regression
nbins=nlearning/block_l;
Bs_prev_vec=reshape(Bs_prev,[],1);
Bs_cur_vec=reshape(Bs_cur,[],1);
Betas=[Bs_prev_vec;Bs_cur_vec];
SN=repmat((1:nsubs)',nbins*2,1);
BIN_singleType=reshape(repmat(1:nbins,nsubs,1),[],1);
BIN=repmat(BIN_singleType,2,1);
Type=[zeros(nsubs*nbins,1);ones(nsubs*nbins,1)];
T = table(SN,BIN,Type,Betas);
save('AdaptPavlovEffects_table','T');
writetable(T,'AdaptPavlovEffects_table.csv');
lme = fitlme(T,'Betas ~ BIN * Type + (1 | SN)','FitMethod','REML');
[beta,betanames,stats_Fixed] = fixedEffects(lme,'DFMethod','satterthwaite');
[B,Bnames,stats_Random] = randomEffects(lme,'DFMethod','satterthwaite');
stats = anova(lme,'DFMethod','satterthwaite');
pVal = coefTest(lme);
%% PLOT SIM
% SS (plotted on top ot the RW sim)
bins=1:nlearning/block_l;
xLim=[0.8 12.2];
yLim=[-0.5 4.5];
figure('position',figSize);
hold on
for p=1:2
if p==1
Bs_SS=Bs_prev_sim_SS;
Bs_RW=Bs_prev_sim_RW;
else
Bs_SS=Bs_cur_sim_SS;
Bs_RW=Bs_cur_sim_RW;
end
mBs_SS=nanmean(Bs_SS);
seBs_SS=nanstd(Bs_SS)/sqrt(nsubs);
varBs_SS=[mBs_SS-seBs_SS;mBs_SS+seBs_SS];
mBs_RW=nanmean(Bs_RW);
seBs_RW=nanstd(Bs_RW)/sqrt(nsubs);
varBs_RW=[mBs_RW-seBs_RW;mBs_RW+seBs_RW];
plot(bins,mBs_SS,':','color',.9*co(p,:),'linewidth',3);
plot(bins,mBs_RW,'-','color',.9*co(p,:),'linewidth',5);
end
xlim(xLim)
ylim(yLim)
xlabel('Bin (50 trials)','fontsize',afs);
ylabel('Regression \beta','fontsize',afs);
set(gca,'xtick',2:2:12,'ytick',0:1:4,'fontsize',tfs);
box off;
|