clear all; clc;
Subj=[1:10];
Cond={'L1','L2','L3','L4'};
%% compute averaged data
for i=1:length(Subj)
setname=strcat(num2str(i),'_LH.set');
setpath='E:\sygs\5EEG1\day23\Example_data\';
EEG= pop_loadset('filename',setname,'filepath',setpath);
EEG= eeg_checkset( EEG );
for j=1:length(Cond)
EEG_new = pop_epoch( EEG, Cond(j), [-1 2], 'newname', 'Merged datasets pruned with ICA epochs epochs', 'epochinfo', 'yes');
EEG_new = eeg_checkset( EEG_new );
EEG_new = pop_rmbase( EEG_new, [-1000 0]);
EEG_new = eeg_checkset( EEG_new );
EEG_avg(i,j,:,:)=squeeze(mean(EEG_new.data,3)); %% subj*cond*channel*timepoints
end
end
%% point-by-point paried t-test across multiple time points 点对点
data_test=squeeze(EEG_avg(:,:,13,:)); %% select the data at Cz, data_test: subj*cond*time
for i=1:size(data_test,3)
data_1=squeeze(data_test(:,3,i)); %% select condition L3 for each time point
data_2=squeeze(data_test(:,4,i)); %% select condition L4 for each time point
[h p]=ttest(data_1,data_2); %% ttest comparison
P_ttest(i)=p; %% save the p value from ttest
end
figure;
subplot(211); plot(EEG.times,squeeze(mean(data_test(:,3,:),1)),'b'); %% plot the average waveform for Condition L3
hold on; plot(EEG.times,squeeze(mean(data_test(:,4,:),1)),'r'); %% plot the average waveform for Condition L4
subplot(212); plot(EEG.times,P_ttest); ylim([0 0.05]); %%plot the p values from ttest
%% point-by-point paried t-test across multiple channels 多通道点对点
test_idx=find((EEG.times>=197)&(EEG.times<=217)); %% define the intervals
data_test=squeeze(mean(EEG_avg(:,:,:,test_idx),4)); %% select the data in [197 217]ms, subj*cond*channel
for i=1:size(data_test,3)
data_1=squeeze(data_test(:,3,i)); %% select condition L3 for each channel
data_2=squeeze(data_test(:,4,i)); %% select condition L4 for each channel
[h,p,ci,stats]=ttest(data_1,data_2); %% ttest comparison
P_ttest2(i)=p; %% save the p value from ttest
T_ttest2(i)=stats.tstat;
end
figure;
subplot(131);
topoplot(squeeze(mean(data_test(:,3,:),1)),EEG.chanlocs,'maplimits',[-20 20]);
subplot(132);
topoplot(squeeze(mean(data_test(:,4,:),1)),EEG.chanlocs,'maplimits',[-20 20]);
% subplot(133);
% topoplot(P_ttest2,EEG.chanlocs,'maplimits',[0 0.05]);
subplot(133);
topoplot(T_ttest2,EEG.chanlocs); %t值的地形图
%% point-by-point repeated measures of ANOVA across time points
data_test=squeeze(EEG_avg(:,:,13,:)); %% select the data at Cz13, data_test: subj*cond*time
for i=1:size(data_test,3)
data_anova=squeeze(data_test(:,:,i)); %% select the data at time point i
[p, table] = anova_rm(data_anova,'off'); %% perform repeated measures ANOVA
P_anova(i)=p(1); %% save the data from ANOVA
end
Cz=13;
mean_data=squeeze(mean(data_test,1)); %% dimension: cond*time
figure;
subplot(211);plot(EEG.times, mean_data,'linewidth', 1.5); %% waveform for different condition
set(gca,'YDir','reverse');
axis([-500 1000 -35 25]);
subplot(212);plot(EEG.times,P_anova); axis([-500 1000 0 0.05]); %% plot the p values from ANOVA
%% point-by-point repeated measures of ANOVA across channels
test_idx=find((EEG.times>=197)&(EEG.times<=217)); %% define the intervals
data_test=squeeze(mean(EEG_avg(:,:,:,test_idx),4)); %% select the data in [197 217]ms, subj*cond*channel
for i=1:size(data_test,3)
data_anova=squeeze(data_test(:,:,i)); %% select the data at channel i
[p, table] = anova_rm(data_anova,'off'); %% perform repeated measures ANOVA重复测量列
P_anova2(i)=p(1); %% save the data from ANOVA
F_anova2(i)=table{2,5};
end
figure;
for i=1:4
subplot(1,5,i);
topoplot(squeeze(mean(data_test(:,i,:),1)),EEG.chanlocs,'maplimits',[-20 20]);
end
% subplot(1,5,5); topoplot( P_anova2,EEG.chanlocs,'maplimits',[0 0.05]);
subplot(1,5,5); topoplot( F_anova2,EEG.chanlocs);
评论0