Skip to content

Commit

Permalink
import functions update (import, design, etc)
Browse files Browse the repository at this point in the history
also 3D-4D-5D reshaping wasn't working
  • Loading branch information
CPernet committed Feb 4, 2014
1 parent 3cc0e67 commit feb4b30
Show file tree
Hide file tree
Showing 18 changed files with 1,068 additions and 616 deletions.
48 changes: 38 additions & 10 deletions limo_design_matrix.m
Expand Up @@ -405,17 +405,45 @@
Yr = limo_match_elec(chanlocs,expected_chanlocs,1,size(Yr,2),Yr);
end

% no matter the analysis we have Beta, Yhat, Res
Yhat = zeros(size(Yr,1),size(Yr,2),size(Yr,3)); save Yhat Yhat; clear Yhat
Res = zeros(size(Yr,1),size(Yr,2),size(Yr,3)); save Res Res; clear Res
Betas = zeros(size(Yr,1),size(Yr,2),size(X,2)); save Betas Betas; clear Betas

% only for univariate analyses
if strcmp(type_of_analysis,'Mass-univariate')
R2 = zeros(size(Yr,1),size(Yr,2),3); save R2 R2;
try
% no matter the analysis we have Beta, Yhat, Res - create them all here
% also R2 for univariate analyses - also test if memory hold for tmp
% files to be created in limo_eeg
Yhat = zeros(size(Yr,1),size(Yr,2),size(Yr,3));
Res = zeros(size(Yr,1),size(Yr,2),size(Yr,3));
Betas = zeros(size(Yr,1),size(Yr,2),size(X,2));

% only for univariate analyses
if strcmp(type_of_analysis,'Mass-univariate')
R2 = zeros(size(Yr,1),size(Yr,2),3); save R2 R2;
end

% these ones will be created in limo_eeg
if nb_conditions ~=0
tmp_Condition_effect = NaN(size(Yr,1),size(Yr,2),length(nb_conditions),2);
end

if nb_interactions ~=0
tmp_Interaction_effect = NaN(size(Yr,1),size(Yr,2),length(nb_interactions),2);
end

if nb_continuous ~=0
tmp_Covariate_effect = NaN(size(Yr,1),size(Yr,2),nb_continuous,2);
end

save Yhat Yhat; clear Yhat
save Betas Betas; clear Betas
save Res Res; clear Res
save Yr Yr ; clear Yr R2

if nb_conditions ~=0; clear tmp_Condition_effect; end
if nb_interactions ~=0; clear tmp_Interaction_effect; end
if nb_continuous ~=0; clear tmp_Covariate_effect; end

catch FileError
sprintf(FileError)
error('error while memory mapping futur results')
end
save Yr Yr ; clear Yr R2


% ------
% figure
Expand Down
80 changes: 40 additions & 40 deletions limo_display_results.m

Large diffs are not rendered by default.

88 changes: 57 additions & 31 deletions limo_eeg.m
Expand Up @@ -131,11 +131,6 @@ function limo_eeg(varargin)
LIMO.data.neighbouring_matrix = channeighbstructmat;
save LIMO LIMO
end
% make H0 and tfce directories
mkdir H0;
if LIMO.design.tfce == 1
mkdir TFCE;
end
end
disp('import done');

Expand Down Expand Up @@ -182,37 +177,37 @@ function limo_eeg(varargin)
% Load either elec voltage over time, elec power over frequency, or
% electrode time-frequency - depending on declared analysis

if LIMO.analysis_flag == 1 % Electrode time values
if strcmp(LIMO.Analysis,'Time')
Y = EEG.data(:,LIMO.data.trim1:LIMO.data.trim2,:);
clear EEG

elseif LIMO.analysis_flag == 2 % Frequency power values
elseif strcmp(LIMO.Analysis,'Frequency')
Y = EEG.etc.limo_psd(:,LIMO.data.trim1:LIMO.data.trim2,:);
clear EEG

elseif LIMO.analysis_flag == 3 % Time-Frequency power values
elseif strcmp(LIMO.Analysis,'Time-Frequency')
clear EEG; disp('Time-Frequency implementation - loading tf data...');
Y=load(LIMO.data.tf_data_filepath); % Load tf data from path in *.set from import stage
Y=Y.limo_tf(:,LIMO.data.trim_low_f:LIMO.data.trim_high_f,LIMO.data.trim1:LIMO.data.trim2,:);
LIMO.data.size4D=size(Y);
LIMO.data.freq_list=repmat(LIMO.data.tf_freqs,[1 numel(LIMO.data.tf_times)]);
LIMO.data.size3D= [LIMO.data.size4D(1) numel(LIMO.data.tf_freqs)*numel(LIMO.data.tf_times) LIMO.data.size4D(4)];
LIMO.data.size3D= [LIMO.data.size4D(1) LIMO.data.size4D(2)*LIMO.data.size4D(3) LIMO.data.size4D(4)];
save LIMO LIMO
end

clear ALLCOM ALLEEG CURRENTSET CURRENTSTUDY LASTCOM STUDY
cd (LIMO.dir)

% make the design matrix
disp('compute design matrix');

if LIMO.analysis_flag == 1 || LIMO.analysis_flag == 2 % For electrode time or power data, limo_design_matrix
[LIMO.design.X, LIMO.design.nb_conditions, LIMO.design.nb_interactions,...
LIMO.design.nb_continuous] = limo_design_matrix(Y, LIMO,1);
elseif LIMO.analysis_flag == 3 % For 4D time-frequency data, use limo_design_matrix_tf
disp('computing design matrix');
if strcmp(LIMO.Analysis,'Time-Frequency') % use limo_design_matrix_tf
[LIMO.design.X, LIMO.design.nb_conditions, LIMO.design.nb_interactions,...
LIMO.design.nb_continuous] = limo_design_matrix_tf(Y, LIMO,1);
LIMO.design.nb_continuous] = limo_design_matrix_tf(Y, LIMO,1);
else % for time or power use limo_design_matrix
[LIMO.design.X, LIMO.design.nb_conditions, LIMO.design.nb_interactions,...
LIMO.design.nb_continuous] = limo_design_matrix(Y, LIMO,1);
end

% update LIMO.mat
if prod(LIMO.design.nb_conditions) > 0 && LIMO.design.nb_continuous == 0
if length(LIMO.design.nb_conditions) == 1
Expand Down Expand Up @@ -258,7 +253,7 @@ function limo_eeg(varargin)

a = questdlg('run the analysis?','Start GLM analysis','Yes','No','Yes');
if strcmp(a,'Yes')
if LIMO.analysis_flag == 3 % For tf data
if strcmp(LIMO.Analysis,'Time-Frequency')
limo_eeg_tf(4);
limo_eeg_tf(5);
else
Expand Down Expand Up @@ -524,7 +519,6 @@ function limo_eeg(varargin)
end

warning off;
W = LIMO.design.weights;
X = LIMO.design.X;
h = waitbar(0,'bootstraping data','name','% done');
for e = 1:size(array,1)
Expand All @@ -537,7 +531,6 @@ function limo_eeg(varargin)
model = limo_glm1_boot(Y(:,index)',X(index,:),LIMO.design.nb_conditions,LIMO.design.nb_interactions,LIMO.design.nb_continuous,LIMO.design.zscore,LIMO.design.method,boot_table{electrode});
else
% index = [1:size(Yr,3)];
LIMO.design.weights = squeeze(W(electrode,:));
model = limo_glm1_boot(squeeze(Yr(electrode,:,:))',LIMO,boot_table);
end

Expand Down Expand Up @@ -640,7 +633,7 @@ function limo_eeg(varargin)
% --------------
if LIMO.design.tfce == 1
load Yr;
if isfield(LIMO.data,'neighbouring_matrix') && size(Yr,1) > 1 && LIMO.design.bootstrap ~=0
if isfield(LIMO.data,'neighbouring_matrix') 1 && LIMO.design.bootstrap ~=0
clear Yr;
if exist('TFCE','dir')
if strcmp(questdlg('TFCE directory detected, overwrite?','data check','Yes','No','No'),'No');
Expand All @@ -653,27 +646,44 @@ function limo_eeg(varargin)

% R2
load R2.mat; fprintf('Creating R2 TFCE scores \n'); cd('TFCE');
tfce_score = limo_tfce(squeeze(R2(:,:,2)),LIMO.data.neighbouring_matrix);
if size(R2,1) == 1
tfce_score(1,:) = limo_tfce(1, squeeze(R2(:,:,2)),LIMO.data.neighbouring_matrix);
else
tfce_score = limo_tfce(2, squeeze(R2(:,:,2)),LIMO.data.neighbouring_matrix);
end
save('tfce_R2','tfce_score'); clear R2; cd ..;

cd('H0'); fprintf('Thresholding H0_R2 using TFCE \n'); load H0_R2;
tfce_H0_score = limo_tfce(squeeze(H0_R2(:,:,2,:)),LIMO.data.neighbouring_matrix);
if size(H0_R2,1) == 1
tfce_H0_score(1,:,:) = limo_tfce(1, squeeze(H0_R2(:,:,2,:)),LIMO.data.neighbouring_matrix);
else
tfce_H0_score = limo_tfce(2, squeeze(H0_R2(:,:,2,:)),LIMO.data.neighbouring_matrix);
end
save('tfce_H0_R2','tfce_H0_score'); clear H0_R2; cd ..;

% conditions
if prod(LIMO.design.nb_conditions) ~=0
for i=1:length(LIMO.design.nb_conditions)
name = sprintf('Condition_effect_%g.mat',i); load(name);
cd('TFCE'); fprintf('Creating Condition %g TFCE scores \n',i)
tfce_score = limo_tfce(squeeze(Condition_effect(:,:,1)),LIMO.data.neighbouring_matrix);
if size(Condition_effect,1) == 1
tfce_score(1,:) = limo_tfce(1, squeeze(Condition_effect(:,:,1)),LIMO.data.neighbouring_matrix);
else
tfce_score = limo_tfce(2, squeeze(Condition_effect(:,:,1)),LIMO.data.neighbouring_matrix);

end
full_name = sprintf('tfce_%s',name); save(full_name,'tfce_score');
clear Condition_effect tfce_score; cd ..
end

cd('H0'); fprintf('Creating H0 Condition(s) TFCE scores \n');
for i=1:length(LIMO.design.nb_conditions)
name = sprintf('H0_Condition_effect_%g.mat',i); load(name);
tfce_H0_score(:,:,:) = limo_tfce(squeeze(H0_Condition_effect(:,:,1,:)),LIMO.data.neighbouring_matrix);
if size(H0_Condition_effect,1)
tfce_H0_score(1,:,:) = limo_tfce(1,squeeze(H0_Condition_effect(:,:,1,:)),LIMO.data.neighbouring_matrix);
else
tfce_H0_score = limo_tfce(2,squeeze(H0_Condition_effect(:,:,1,:)),LIMO.data.neighbouring_matrix);
end
full_name = sprintf('tfce_%s',name); save(full_name,'tfce_H0_score');
clear H0_Condition_effect tfce_H0_score;
end
Expand All @@ -685,15 +695,23 @@ function limo_eeg(varargin)
for i=1:length(LIMO.design.fullfactorial)
name = sprintf('Interaction_effect_%g.mat',i); load(name);
cd('TFCE'); fprintf('Creating Interaction %g TFCE scores \n',i)
tfce_score = limo_tfce(squeeze(Interaction_effect(:,:,1)),LIMO.data.neighbouring_matrix);
if size(Interaction_effect,1) == 1
tfce_score(1,:) = limo_tfce(1,squeeze(Interaction_effect(:,:,1)),LIMO.data.neighbouring_matrix);
else
tfce_score = limo_tfce(2,squeeze(Interaction_effect(:,:,1)),LIMO.data.neighbouring_matrix);
end
full_name = sprintf('tfce_%s',name); save(full_name,'tfce_score');
clear Interaction_effect tfce_score; cd ..
end

cd('H0'); fprintf('Creating H0 Interaction(s) TFCE scores \n');
for i=1:length(LIMO.design.fullfactorial)
name = sprintf('H0_Interaction_effect_%g.mat',i); load(name);
tfce_H0_score(:,:,:) = limo_tfce(squeeze(H0_Interaction_effect(:,:,1,:)),LIMO.data.neighbouring_matrix);
if size(H0_Interaction_effect,1) == 1
tfce_H0_score(1,:,:) = limo_tfce(1,squeeze(H0_Interaction_effect(:,:,1,:)),LIMO.data.neighbouring_matrix);
else
tfce_H0_score = limo_tfce(2,squeeze(H0_Interaction_effect(:,:,1,:)),LIMO.data.neighbouring_matrix);
end
full_name = sprintf('tfce_%s',name); save(full_name,'tfce_H0_score');
clear H0_Interaction_effect tfce_H0_score;
end
Expand All @@ -705,24 +723,32 @@ function limo_eeg(varargin)
for i=1:LIMO.design.nb_continuous
name = sprintf('Covariate_effect_%g.mat',i); load(name);
cd('TFCE'); fprintf('Creating Covariate %g TFCE scores \n',i);
tfce_score = limo_tfce(squeeze(Covariate_effect(:,:,1)),LIMO.data.neighbouring_matrix);
if size(Covariate_effect,1) == 1
tfce_score(1,:) = limo_tfce(1,squeeze(Covariate_effect(:,:,1)),LIMO.data.neighbouring_matrix);
else
tfce_score = limo_tfce(2,squeeze(Covariate_effect(:,:,1)),LIMO.data.neighbouring_matrix);
end
full_name = sprintf('tfce_%s',name); save(full_name,'tfce_score');
clear Covariate_effect tfce_score; cd ..
end

cd('H0'); fprintf('Creating H0 Covariate(s) TFCE scores \n');
for i=1:LIMO.design.nb_continuous
name = sprintf('H0_Covariate_effect_%g.mat',i); load(name);
tfce_H0_score(:,:,:) = limo_tfce(squeeze(H0_Covariate_effect(:,:,1,:)),LIMO.data.neighbouring_matrix);
if size(H0_Covariate_effect,1)
tfce_H0_score(1,:,:) = limo_tfce(1,squeeze(H0_Covariate_effect(:,:,1,:)),LIMO.data.neighbouring_matrix);
else
tfce_H0_score = limo_tfce(2,squeeze(H0_Covariate_effect(:,:,1,:)),LIMO.data.neighbouring_matrix);
end
full_name = sprintf('tfce_%s',name); save(full_name,'tfce_H0_score');
clear H0_Covariate_effect tfce_H0_score
end
cd ..
end
elseif ~isfield(LIMO.data,'neighbouring_matrix')
disp('No TFCE performed, neighbourhood matrix missing')
elseif size(Yr,1) == 1
disp('No TFCE performed, only 1 electrode')
elseif LIMO.design.bootstrap ==0
disp('No TFCE performed, since there was no bootstraps computed')
end
end

Expand Down

0 comments on commit feb4b30

Please sign in to comment.