-
Notifications
You must be signed in to change notification settings - Fork 28
/
limo_get_summary.m
112 lines (100 loc) · 3.5 KB
/
limo_get_summary.m
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
function [clusters,madeupclusters] = limo_get_summary(file,mask)
% simple routine to compute summary statistics per cluster
%
% FORMAT clusters = limo_get_summary(file,mask)
%
% INPUTS file is a result file like a t-test or ANOVA
% mask is a N-ary matrix of clusters, if binary it will try to make
% up clusters
%
% OUTPUTS clusters, a structure with summary statistics per cluster
% - eigenmode is the 'direction' of the effect size (usually,
% clusters are right skewed and thus it represents
% better the 'average' effect size)
% - median provided as a comparison point to eigen mode
% - mean provided as a comparison point to eigen mode
% - min and max for completeness
%
% Cyril Pernet 2022
% ------------------------------
% Copyright (C) LIMO Team 2022
clusters = [];
%% check inputs
if nargin == 0
% no input, ask user to select a file
[file,filepath] = uigetfile('.mat','select a LIMO stat file');
if isempty(file)
return
else
file = fullfile(filepath,file);
end
% no input, check if user want to use current mask
ismask = evalin( 'base', 'exist(''mask'',''var'') == 1' );
if ismask
mask = evalin('base','mask');
else
if exist('errordlg2','file')
errordlg2('no mask file found in the workspace, image the statistical results to create one and call this function again')
else
errordlg('no mask file found in the workspace, image the statistical results to create one and call this function again')
end
end
end
[filepath,filename,ext]=fileparts(file);
if isempty(filepath)
filepath = pwd;
end
filename = [filename ext];
if ~exist(fullfile(filepath,filename),'file')
error('file %s not found', filename)
end
if ~exist(fullfile(filepath,'LIMO.mat'),'file')
error('cannot find a LIMO.mat in the same filder as this file, this is required for this function to work')
else
LIMO = load(fullfile(filepath,'LIMO.mat'));
LIMO = LIMO.LIMO;
end
%% get data
stats = load(fullfile(filepath,filename));
stats = stats.(cell2mat(fieldnames(stats)));
if contains(filename,'one_sample','IgnoreCase',true) || contains(filename,'two_samples','IgnoreCase',true) || ...
contains(filename,'paired_samples','IgnoreCase',true) || contains(filename,'con_','IgnoreCase',true) || ...
contains(filename,'ess_','IgnoreCase',true)
if numel(size(stats)) == 3
stats = squeeze(stats(:,:,4));
else
stats = squeeze(stats(:,:,:,4));
end
elseif contains(filename,'R2.mat') || contains(filename,'semi_partial_coef')
if numel(size(stats)) == 3
stats = squeeze(stats(:,:,2));
else
stats = squeeze(stats(:,:,:,2));
end
else
if numel(size(stats)) == 3
stats = squeeze(stats(:,:,1));
else
stats = squeeze(stats(:,:,:,1));
end
end
%% deal with clusters
% --------------------
% quickly make if N-ary if binary
if length(unique(mask)) == 2
mask = limo_findcluster(mask,LIMO.data.neighbouring_matrix,2);
end
num = unique(mask);
num(num==0) = [];
for c = length(num):-1:1
data = stats(mask == num(c));
clusters(c).eigenmode = sqrt(eig(data'*data)/length(data));
clusters(c).median = median(data);
clusters(c).mean = mean(data);
clusters(c).min = min(data);
clusters(c).max = max(data);
if nargout == 0
assignin('base','clusters_summary_stats',clusters)
end
end
madeupclusters = mask;