load('Figure3Data.mat')

%%
SST_cumvals = nan(150,size(SSTCumVals,1));
for i = 1:size(SSTCumVals,1)
    cumvals = SSTCumVals{i};
    if size(cumvals,1) < 150
        SST_cumvals(1:size(cumvals,1),i) = cumvals;
    else
        SST_cumvals(:,i) = cumvals(1:150);
    end
end

%%
BacL1_cumvals = BacL1_cumvals(1:100,:);
SST_cumvals = SST_cumvals(1:100,:);

%%
figure
errorbar(nanmean(Control_cumvals,2),nanstd(Control_cumvals,[],2)/sqrt(11),'k')

hold on
errorbar(nanmean(BacL1_cumvals,2),nanstd(BacL1_cumvals,[],2)/sqrt(6),'r')

errorbar(nanmean(SST_cumvals,2),nanstd(SST_cumvals,[],2)/sqrt(6),'b')

xlim([0 100])
ylabel('Cummulative Sum')
xlabel('trial #')



%%


for i =1:size(BacL1_cumvals,2)
    plot(BacL1_cumvals(:,i),'r')
    hold on
end


for i =1:size(SST_cumvals,2)
    plot(SST_cumvals(:,i),'b')
    hold on
end
legend({'Control (n=20)', 'BacL1 (n=6)',  'SST (n=6)'})
ylim([-100 100])
set(gca,'YTick', -100:50:100)
%%

figure
PlotAllDataPoints3(Ctrl, BacL1, SSTNormCumSumLastVal)


set(gca, 'XTick',1:3, 'XTickLabel', {'Ctrl','Baclofen', 'SST'})

ylabel('Normalized learning score')
xlim([0.5 3.5])

%%
group = [ones(20,1); ones(6,1)+1; ones(6,1)+2];

[p,tbl,stats] = kruskalwallis([Ctrl; BacL1; SSTNormCumSumLastVal'],group,'off')

c = multcompare(stats,'CType', 'dunn-sidak')


%%
[p1 h] = ranksum(Ctrl, BacL1)

[p2 h] = ranksum(Ctrl, SSTNormCumSumLastVal)

text(1.8, 0.7, ['p = ', num2str(p1)])
text(2.8, 0.7, ['p = ', num2str(p2)])

ylim([-1 1])
set(gca,'YTick', [-1:0.5:1])
