Brown2020 / scripts /BEH_VV_CTL.m
jalauer's picture
Add files using upload-large-folder tool
227148b verified
%% Calculate Data
clear all; clc
datapath=('Y:\EEG_Data\PDDys\BEH\');
cd(datapath);
SUBJS=[8010,8070,8060,890:914];
for subno=SUBJS
for session=1
disp(['VV Beh --- Subno: ',num2str(subno),' Session: ',num2str(session)]); disp(' ');
% TRAIN
fileID=dir([num2str(subno),'_S',num2str(session),'*']);
load(fileID.name); clear fileID
% ----- Columns are: -----
% 1 = block
% 2 = trial
% 3 = (cTrialID)
% 4 = Forced choice
% 6 = S1
% 8 = S2
% 10 = S1 is left
% 11 = Stim Selected
% 13 = Reward (1 or 0)
% 14 = RT
% ----------- Re-make With More Simpleness
ABchoose=[1,2]; CDchoose=[3,4]; WXmatch=[5,6]; YZmatch=[7,8];
for ai=1:length(task_struct.trainTrials)
if any(task_struct.trainTrials(ai,6)==ABchoose)
CONDI=1;
elseif any(task_struct.trainTrials(ai,6)==CDchoose)
CONDI=2;
elseif any(task_struct.trainTrials(ai,6)==WXmatch)
CONDI=3;
elseif any(task_struct.trainTrials(ai,6)==YZmatch)
CONDI=4;
end
TRAIN(ai,1)=CONDI; clear CONDI; % Condi: 1=ABchoose 2=CDchoose 3=ABmatch 4=CDmatch
TRAIN(ai,2)=mod(task_struct.trainTrials(ai,11),2); % Optimal choice (odd num are optimal: 1,3,5,7)
TRAIN(ai,3)=task_struct.trainTrials(ai,14); % RT
TRAIN(ai,4)=task_struct.trainTrials(ai,13); % was rewarded or not
end
% ----------- Re-make With More Simpleness
for ai=1:length(task_struct.testTrials)
ThisSet=task_struct.testTrials(ai,[6,8]);
ThisSet=str2num(cat(2,num2str(ThisSet(1)),num2str(ThisSet(2))));
ThisChoice=task_struct.testTrials(ai,11);
if any(ThisSet==[12,21]), CONDI='AB';
elseif any(ThisSet==[13,31]), CONDI='AC';
elseif any(ThisSet==[14,41]), CONDI='AD';
elseif any(ThisSet==[15,51]), CONDI='AW';
elseif any(ThisSet==[16,61]), CONDI='AX';
elseif any(ThisSet==[17,71]), CONDI='AY';
elseif any(ThisSet==[18,81]), CONDI='AZ';
elseif any(ThisSet==[23,32]), CONDI='BC';
elseif any(ThisSet==[24,42]), CONDI='BD';
elseif any(ThisSet==[25,52]), CONDI='BW';
elseif any(ThisSet==[26,62]), CONDI='BX';
elseif any(ThisSet==[27,72]), CONDI='BY';
elseif any(ThisSet==[28,82]), CONDI='BZ';
elseif any(ThisSet==[34,43]), CONDI='CD';
elseif any(ThisSet==[35,53]), CONDI='CW';
elseif any(ThisSet==[36,63]), CONDI='CX';
elseif any(ThisSet==[37,73]), CONDI='CY';
elseif any(ThisSet==[38,83]), CONDI='CZ';
elseif any(ThisSet==[45,54]), CONDI='DW';
elseif any(ThisSet==[46,64]), CONDI='DX';
elseif any(ThisSet==[47,74]), CONDI='DY';
elseif any(ThisSet==[48,84]), CONDI='DZ';
elseif any(ThisSet==[56,65]), CONDI='WX';
elseif any(ThisSet==[57,75]), CONDI='WY';
elseif any(ThisSet==[58,85]), CONDI='WZ';
elseif any(ThisSet==[67,76]), CONDI='XY';
elseif any(ThisSet==[68,86]), CONDI='XZ';
elseif any(ThisSet==[78,87]), CONDI='YZ';
end
TEST(ai).condi=CONDI; % Condi
TEST(ai).choice=ThisChoice; % This Choice
TEST(ai).RT=task_struct.testTrials(ai,14); % RT
clear ThisSet ThisChoice CONDI;
end
save([num2str(subno),'_sess',num2str(session),'_VVbeh.mat'],'TRAIN','TEST');
clear task_struct disp_struct AB* CD* TRAIN TEST
end
end
row=0;
for subno=SUBJS
for session=1;
row=row+1;
load([num2str(subno),'_sess',num2str(session),'_VVbeh.mat'],'TRAIN','TEST');
MEGA(row).ID=subno;
MEGA(row).session=session;
MEGA(row).TRN_blocks=size(TRAIN,1)./40;
MEGA(row).TRN_ACC=mean(TRAIN(:,2));
MEGA(row).TRN_RT=mean(TRAIN(:,3));
for bi=1:4 % Condi: 1=ABchoose 2=CDchoose 3=ABmatch 4=CDmatch
MINISET=TRAIN(TRAIN(:,1)==bi,:);
MINISET(:,[5,6])=[MINISET(2:end,[2,3]);[NaN,NaN]];
MINISET(:,6)=MINISET(:,6)-MINISET(:,3); % RT diff
% --------
WINS=MINISET(MINISET(:,4)==1,[2,5,6]);
LOSSES=MINISET(MINISET(:,4)==0,[2,5,6]);
% --------
WinStay(bi)=mean(WINS(:,1)==WINS(:,2));
LoseSwitch(bi)=mean(LOSSES(:,1)~=LOSSES(:,2));
WinSpeed(bi)=mean(WINS(WINS(:,1)==WINS(:,2),3));
% --------
clear MINISET WINS LOSSES
end
MEGA(row).WinStay=WinStay;
MEGA(row).LoseSwitch=LoseSwitch;
MEGA(row).WinSpeed=WinSpeed;
% ********************************************************
for ci=1:128
RT(ci,1)=TEST(ci).RT;
% ^^^^ General Accuracy A,B,C,D == W,X,Y,Z - 4 of each set
ACC=NaN; PARSE=NaN;
if strmatch(TEST(ci).condi,'AB');
if TEST(ci).choice==1, ACC=1; elseif TEST(ci).choice==2, ACC=0; end; PARSE=1;
elseif strmatch(TEST(ci).condi,'WX');
if TEST(ci).choice==5, ACC=1; elseif TEST(ci).choice==6, ACC=0; end; PARSE=2;
elseif strmatch(TEST(ci).condi,'CD');
if TEST(ci).choice==3, ACC=1; elseif TEST(ci).choice==4, ACC=0; end; PARSE=3;
elseif strmatch(TEST(ci).condi,'YZ');
if TEST(ci).choice==7, ACC=1; elseif TEST(ci).choice==8, ACC=0; end; PARSE=4;
end
% ^^^^ free vs. forced A,B,C,D == W,X,Y,Z - 8 of each set
BIAS=NaN;
if strmatch(TEST(ci).condi,'AW');
if TEST(ci).choice==1, BIAS=1; elseif TEST(ci).choice==5, BIAS=0; end; PARSE=5;
elseif strmatch(TEST(ci).condi,'CY');
if TEST(ci).choice==3, BIAS=1; elseif TEST(ci).choice==7, BIAS=0; end; PARSE=6;
elseif strmatch(TEST(ci).condi,'DZ');
if TEST(ci).choice==4, BIAS=1; elseif TEST(ci).choice==8, BIAS=0; end; PARSE=7;
elseif strmatch(TEST(ci).condi,'BX');
if TEST(ci).choice==2, BIAS=1; elseif TEST(ci).choice==6, BIAS=0; end; PARSE=8;
end
% ^^^^
WITHINSET=NaN;
if strmatch(TEST(ci).condi,'AC');
if TEST(ci).choice==1, WITHINSET=1; elseif TEST(ci).choice==3, WITHINSET=0; end; PARSE=9;
elseif strmatch(TEST(ci).condi,'AD');
if TEST(ci).choice==1, WITHINSET=1; elseif TEST(ci).choice==4, WITHINSET=0; end; PARSE=10;
elseif strmatch(TEST(ci).condi,'BC');
if TEST(ci).choice==3, WITHINSET=1; elseif TEST(ci).choice==2, WITHINSET=0; end; PARSE=11;
elseif strmatch(TEST(ci).condi,'BD');
if TEST(ci).choice==4, WITHINSET=1; elseif TEST(ci).choice==2, WITHINSET=0; end; PARSE=12;
elseif strmatch(TEST(ci).condi,'WY');
if TEST(ci).choice==5, WITHINSET=1; elseif TEST(ci).choice==7, WITHINSET=0; end; PARSE=13;
elseif strmatch(TEST(ci).condi,'WZ');
if TEST(ci).choice==5, WITHINSET=1; elseif TEST(ci).choice==8, WITHINSET=0; end; PARSE=14;
elseif strmatch(TEST(ci).condi,'XY');
if TEST(ci).choice==7, WITHINSET=1; elseif TEST(ci).choice==6, WITHINSET=0; end; PARSE=15;
elseif strmatch(TEST(ci).condi,'XZ');
if TEST(ci).choice==8, WITHINSET=1; elseif TEST(ci).choice==6, WITHINSET=0; end; PARSE=16;
end
% ^^^^
EASY=NaN;
if strmatch(TEST(ci).condi,'AX');
if TEST(ci).choice==1, EASY=1; elseif TEST(ci).choice==5, EASY=0; end; PARSE=17;
elseif strmatch(TEST(ci).condi,'AY');
if TEST(ci).choice==1, EASY=1; elseif TEST(ci).choice==7, EASY=0; end; PARSE=18;
elseif strmatch(TEST(ci).condi,'AZ');
if TEST(ci).choice==1, EASY=1; elseif TEST(ci).choice==8, EASY=0; end; PARSE=19;
elseif strmatch(TEST(ci).condi,'BW');
if TEST(ci).choice==5, EASY=1; elseif TEST(ci).choice==2, EASY=0; end; PARSE=20;
elseif strmatch(TEST(ci).condi,'CW');
if TEST(ci).choice==5, EASY=1; elseif TEST(ci).choice==3, EASY=0; end; PARSE=21;
elseif strmatch(TEST(ci).condi,'DW');
if TEST(ci).choice==5, EASY=1; elseif TEST(ci).choice==4, EASY=0; end; PARSE=22;
end
% ^^^^
MEDIUM=NaN;
if strmatch(TEST(ci).condi,'CX');
if TEST(ci).choice==3, MEDIUM=1; elseif TEST(ci).choice==6, MEDIUM=0; end; PARSE=23;
elseif strmatch(TEST(ci).condi,'CZ');
if TEST(ci).choice==3, MEDIUM=1; elseif TEST(ci).choice==8, MEDIUM=0; end; PARSE=24;
elseif strmatch(TEST(ci).condi,'BY');
if TEST(ci).choice==7, MEDIUM=1; elseif TEST(ci).choice==2, MEDIUM=0; end; PARSE=25;
elseif strmatch(TEST(ci).condi,'DY');
if TEST(ci).choice==7, MEDIUM=1; elseif TEST(ci).choice==4, MEDIUM=0; end; PARSE=26;
end
% ^^^^
HARD=NaN;
if strmatch(TEST(ci).condi,'BZ');
if TEST(ci).choice==8, HARD=1; elseif TEST(ci).choice==2, HARD=0; end; PARSE=27;
elseif strmatch(TEST(ci).condi,'DX');
if TEST(ci).choice==4, HARD=1; elseif TEST(ci).choice==6, HARD=0; end; PARSE=28;
end
% ^^^^
TST_ACC(ci,1)=ACC;
TST_BIAS(ci,1)=BIAS;
TST_WITHINSET(ci,1)=WITHINSET;
TST_EASY(ci,1)=EASY;
TST_MEDIUM(ci,1)=MEDIUM;
TST_HARD(ci,1)=HARD;
TST_PARSE(ci,1)=PARSE;
clear ACC BIAS WITHINSET EASY MEDIUM HARD PARSE;
end
for di=1:4
ACCURACIES(di)=nanmean(TST_ACC(TST_PARSE==di));
end
for di=5:8
BIASES(di-4)=nanmean(TST_BIAS(TST_PARSE==di));
end
for di=9:16
WITHINSETS(di-8)=nanmean(TST_WITHINSET(TST_PARSE==di));
end
for di=17:22
EASYS(di-16)=nanmean(TST_EASY(TST_PARSE==di));
end
for di=23:26
MEDIUMS(di-22)=nanmean(TST_MEDIUM(TST_PARSE==di));
end
for di=27:28
HARDS(di-26)=nanmean(TST_HARD(TST_PARSE==di));
end
MEGA(row).TST_ACC=ACCURACIES;
MEGA(row).TST_BIAS=BIASES;
MEGA(row).TST_WITHINSET=WITHINSETS;
MEGA(row).TST_EASY=EASYS;
MEGA(row).TST_MEDIUM=MEDIUMS;
MEGA(row).TST_HARD=HARDS;
MEGA(row).TST_RT=mean(RT);
clearvars -except MEGA subjcount subno session RT row ONOFF SUBJS;
end
end
save('VV_Behavior_CTL.mat','MEGA');
clear RT row session subno
%%
row=0;
for subno=SUBJS
row=row+1;
CTL.ID(row,:)=MEGA(row).ID;
CTL.session(row,:)=MEGA(row).session;
CTL.TRN_ACC(row,:)=MEGA(row).TRN_ACC;
CTL.TRN_RT(row,:)=MEGA(row).TRN_RT;
CTL.WinStay(row,:)=MEGA(row).WinStay;
CTL.LoseSwitch(row,:)=MEGA(row).LoseSwitch;
CTL.WinSpeed(row,:)=MEGA(row).WinSpeed;
CTL.TST_ACC(row,:)=MEGA(row).TST_ACC;
CTL.TST_BIAS(row,:)=MEGA(row).TST_BIAS;
CTL.TST_WITHINSET(row,:)=MEGA(row).TST_WITHINSET;
CTL.TST_EASY(row,:)=MEGA(row).TST_EASY;
CTL.TST_MEDIUM(row,:)=MEGA(row).TST_MEDIUM;
CTL.TST_HARD(row,:)=MEGA(row).TST_HARD;
CTL.TST_RT(row,:)=MEGA(row).TST_RT;
CTL.Blocks(row,:)=MEGA(mi).TRN_blocks;
end
save('VV_Behavior_CTL.mat','MEGA','CTL');
BigN=length(SUBJS);
jitter=rand(1,BigN)./2.5; jitter=jitter-mean(jitter);
%%
figure;
subplot(1,5,1); hold on
bar(1,mean(CTL.TRN_ACC),'g');
errorbar(1,mean(CTL.TRN_ACC),std(CTL.TRN_ACC)./sqrt(BigN),'k.');
set(gca,'xlim',[0 2],'xtick',[1:1:1],'xticklabel',{'CTL'},'ylim',[.5 1]);
title('TRN Acc');
subplot(1,5,2:3); hold on
bar(1:4,mean(CTL.TST_ACC),.4,'g');
errorbar(1:4,mean(CTL.TST_ACC),std(CTL.TST_ACC)./sqrt(BigN),'k.');
plot(1:4,CTL.TST_ACC,'b.');
set(gca,'xlim',[0 5],'xtick',[1:1:4],'xticklabel',{'AB','WX','CD','YZ'});
title('TST Acc');
subplot(1,5,4:5); hold on
bar(1:4,mean(CTL.TST_BIAS),.4,'g');
errorbar(1:4,mean(CTL.TST_BIAS),std(CTL.TST_BIAS)./sqrt(BigN),'k.');
plot(1:4,CTL.TST_BIAS,'b.');
set(gca,'xlim',[0 5],'xtick',[1:1:4],'xticklabel',{'AW','CY','DZ','BX'});
title('TST BIAS');
%%
% % % clc;
% % % disp([num2str(subno),'_sess',num2str(session),'_VVbeh'])
% % % disp(' ')
% % % disp('Accuracy: >.5 shows that they learned optimal choice')
% % % disp([' choose: AB (90/10)',' match: WX (90/10)',' choose: CD (70/30)',' match: YZ (70/30)'])
% % % disp(['Test Acc: ',num2str(MEGA(row).TST_ACC)])
% % % disp(' ')
% % % disp('BIAS: >.5 is prefer Choose over Match (may only happen for first 2)')
% % % disp([' AW (90/90)',' CY (70/70)',' DZ (30/30)',' BX (30/30)'])
% % % disp(['Test BIAS: ',num2str(MEGA(row).TST_BIAS)])
%%