Skip to content

Commit c2e954b

Browse files
committed
First commit
0 parents  commit c2e954b

11 files changed

+1128
-0
lines changed

.gitattributes

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto
3+
4+
# Custom for Visual Studio
5+
*.cs diff=csharp
6+
7+
# Standard to msysgit
8+
*.doc diff=astextplain
9+
*.DOC diff=astextplain
10+
*.docx diff=astextplain
11+
*.DOCX diff=astextplain
12+
*.dot diff=astextplain
13+
*.DOT diff=astextplain
14+
*.pdf diff=astextplain
15+
*.PDF diff=astextplain
16+
*.rtf diff=astextplain
17+
*.RTF diff=astextplain

.gitignore

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Windows image file caches
2+
Thumbs.db
3+
ehthumbs.db
4+
5+
# Folder config file
6+
Desktop.ini
7+
8+
# Recycle Bin used on file shares
9+
$RECYCLE.BIN/
10+
11+
# Windows Installer files
12+
*.cab
13+
*.msi
14+
*.msm
15+
*.msp
16+
17+
# Windows shortcuts
18+
*.lnk
19+
20+
# =========================
21+
# Operating System Files
22+
# =========================
23+
24+
# OSX
25+
# =========================
26+
27+
.DS_Store
28+
.AppleDouble
29+
.LSOverride
30+
31+
# Thumbnails
32+
._*
33+
34+
# Files that might appear in the root of a volume
35+
.DocumentRevisions-V100
36+
.fseventsd
37+
.Spotlight-V100
38+
.TemporaryItems
39+
.Trashes
40+
.VolumeIcon.icns
41+
42+
# Directories potentially created on remote AFP share
43+
.AppleDB
44+
.AppleDesktop
45+
Network Trash Folder
46+
Temporary Items
47+
.apdisk

Example_2way_indepANOVA.m

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
stemFolder = pwd;
2+
load([stemFolder filesep 'dummy'],'data');
3+
4+
cfg_neighb = [];
5+
cfg_neighb.method = 'template';
6+
cfg_neighb.template = 'CTF275_neighb.mat';
7+
neighbours = ft_prepare_neighbours(cfg_neighb, data);
8+
9+
%% Gender-Dosage test data set
10+
% Test data set from: http://personality-project.org/r/r.guide/r.anova.html
11+
12+
% Indep 2x2 ANOVA: factors Gender & dosage on alertness level
13+
14+
% Design matrix for the test data
15+
design(1,:) = [ones(1,2*4) ones(1,2*4)*2]; % First factor: Gender
16+
design(2,:) = repmat([ones(1,4) ones(1,4)*2],1,2); % Second Factor: Dosage
17+
18+
data.powspctrm = [8 12 13 12 6 7 23 14 15 12 22 14 15 12 18 22]';
19+
20+
% Results given at the personality-project.org page
21+
22+
% Df Sum Sq Mean Sq F value Pr(>F)
23+
% Gender 1 76.562 76.562 2.9518 0.1115
24+
% Dosage 1 5.062 5.062 0.1952 0.6665
25+
% Gender:Dosage 1 0.063 0.063 0.0024 0.9617
26+
% Residuals 12 311.250 25.938
27+
28+
29+
30+
%% Specify configuration structure: the dummy data structure consists of a single channel, time bin and frequency of interest
31+
cfg = [];
32+
33+
cfg.channel = {'MLC11'};
34+
cfg.latency = [1 1];
35+
cfg.frequency = [4 4];
36+
cfg.avgovertime = 'no';
37+
cfg.avgoverfreq = 'no';
38+
cfg.avgoverchan = 'no';
39+
40+
cfg.method = 'montecarlo';
41+
cfg.correctm = 'cluster';
42+
cfg.clusteralpha = 1; % consider all clusters irrespectively of significance
43+
cfg.clusterstatistic = 'maxsum';
44+
cfg.minnbchan = 0; % we are looking at one channel only
45+
46+
cfg.statistic = 'indepAnova2way';
47+
cfg.fac = 'iaxb'; % main effect Gender: 'a', main effect Dosage: 'b' and interaction: 'iaxb'
48+
cfg.tail = 1; % F-values can only take positive values
49+
cfg.clustertail = 1;
50+
cfg.design = design;
51+
cfg.neighbours = neighbours;
52+
cfg.numrandomization = 999; % number of permutations
53+
54+
55+
56+
%% define permutation strategies
57+
main_exact_flag = 'yes';
58+
switch cfg.fac
59+
case 'a'
60+
switch main_exact_flag
61+
case 'no' % unrestricted permutations across levels of both factors
62+
cfg.ivar = [1 2];
63+
cfg.wvar = [];
64+
cfg.uvar = [];
65+
cfg.cvar = [];
66+
case 'yes' % restricted permutations within levels of the other factor (exact test)
67+
cfg.ivar = [1 2];
68+
cfg.wvar = [];
69+
cfg.uvar = [];
70+
cfg.cvar = 2;
71+
end
72+
73+
case 'b'
74+
switch main_exact_flag
75+
case 'no'
76+
cfg.ivar = [1 2];
77+
cfg.wvar = [];
78+
cfg.uvar = [];
79+
cfg.cvar = [];
80+
case 'yes'
81+
cfg.ivar = [1 2];
82+
cfg.wvar = [];
83+
cfg.uvar = [];
84+
cfg.cvar = 1;
85+
end
86+
87+
case 'iaxb' % unrestricted permutations across levels of both factors
88+
cfg.ivar = [1 2];
89+
cfg.wvar = [];
90+
cfg.uvar = [];
91+
cfg.cvar = [];
92+
end
93+
94+
stat = ft_freqstatistics(cfg, data);

FtSimLink_indepANOVA.m

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
function stat = FtSimLink_indepANOVA(data,neighbours,y,design,statfun,fac,main_exact_flag)
2+
3+
data.powspctrm = y'; % data based on a dummy structure
4+
5+
% Specify configuration structure
6+
cfg = [];
7+
8+
cfg.channel = {'MLC11'};
9+
cfg.latency = [1 1];
10+
cfg.frequency = [4 4];
11+
cfg.avgovertime = 'no';
12+
cfg.avgoverfreq = 'no';
13+
cfg.avgoverchan = 'no';
14+
15+
cfg.method = 'montecarlo';
16+
cfg.correctm = 'cluster';
17+
cfg.clusteralpha = 0.05; % threshold for a data entry being a cluster candidate
18+
cfg.clusteralpha = 1; % show all clusters irrespectively of significance
19+
cfg.clusterstatistic = 'maxsum';
20+
cfg.minnbchan = 0; % the dummy data has only one channel
21+
22+
cfg.statistic = statfun;
23+
cfg.tail = 1; % F-values can only take positive values
24+
cfg.clustertail = 1;
25+
cfg.design = design;
26+
cfg.neighbours = neighbours;
27+
cfg.numrandomization = 999; % number of permutations
28+
cfg.fac = fac;
29+
30+
% define permutations to be performed
31+
switch cfg.fac
32+
case 'a' % exact main a
33+
switch main_exact_flag
34+
case 'no'
35+
cfg.ivar = [1 2];
36+
cfg.wvar = [];
37+
cfg.uvar = [];
38+
cfg.cvar = [];
39+
case 'yes'
40+
cfg.ivar = [1 2];
41+
cfg.wvar = [];
42+
cfg.uvar = [];
43+
cfg.cvar = 2;
44+
end
45+
46+
case 'b' % exact main b
47+
switch main_exact_flag
48+
case 'no'
49+
cfg.ivar = [1 2];
50+
cfg.wvar = [];
51+
cfg.uvar = [];
52+
cfg.cvar = [];
53+
case 'yes'
54+
cfg.ivar = [1 2];
55+
cfg.wvar = [];
56+
cfg.uvar = [];
57+
cfg.cvar = 1;
58+
end
59+
60+
case 'iaxb' % a x b interaction
61+
cfg.ivar = [1 2];
62+
cfg.wvar = [];
63+
cfg.uvar = [];
64+
cfg.cvar = [];
65+
end
66+
67+
68+
cfg.design = design';
69+
stat = ft_freqstatistics(cfg, data);

Readme.txt

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
How to set up Fieldtrip
2+
3+
To perform a 2-way balanced, independent (between units of observation) permutation ANOVA:
4+
5+
1.) put the ft_statfun_indepAnova2way.m file into the statfun folder of your current Fieldtrip version
6+
7+
2.) the actual ANOVA calculations are done by the core function anova_cell_mod (adapted from Arnaud Delorme�s resampling statistical toolkit, https://de.mathworks.com/matlabcentral/fileexchange/27960-resampling-statistical-toolkit), which needs to go into the privat subfolder of the statfun folder
8+
9+
3.) Next, you�ll have to modify some Fieldtrip functions. Note that the line numbers given below might be slightly different in your Fieldtrip version. They should give you an idea where to look, though.
10+
11+
In ft_statistics_montecarlo:
12+
1. around line 120 (where the defaults for the main function are set), add the following line to set the default effect of interest to be the interaction:
13+
cfg.fac = ft_getopt(cfg, 'fac','iaxb');
14+
15+
2. starting at line 213, replace the assignment
16+
17+
resample = resampledesign(cfg, design);
18+
19+
with
20+
21+
if isfield(cfg,'resample')
22+
resample = cfg.resample;
23+
else
24+
resample = resampledesign(cfg, design);
25+
end
26+
27+
This will allow you to use some pre-computed, more complex permutation matrices (not necessary for an independent 2-way ANOVA, but e.g. for group x condition interactions in a mixed design)
28+
29+
3. at approximately line 229 add
30+
31+
tmpcfg.fac = cfg.fac;
32+
33+
This configuration struct field will be used to indicate the factor or interaction of interest. This can be 'a' (first factor), 'b' (second factor) or 'iaxb' for the interaction
34+
35+
4. then go to resampledesign (in the private folder of your Fieldtrip version) and change line 130 from
36+
37+
resample = cat(2, blockres{:});
38+
to
39+
resample(:,cat(2, blocksel{:})) = cat(2, blockres{:});
40+
41+
See the following bug note: http://bugzilla.fcdonders.nl/show_bug.cgi?id=1546
42+
43+
Now your Fieldtrip version is set up and ready to run permutation ANOVAs.
44+
45+
You can take a look at the example script and the Sim_indepANOVA_* files (using FtSimLink_indepANOVA; you might want to decrease the number of Monte Carlo simulation to 10 in order to avoid very long running times). Before running the simulation scripts make sure that a copy of anova_cell_mod and the dummy structure are in your working directory (this won�t be necessary if you later run your own analysis in Fieldtrip). The set-up of the design matrix and of the independent and control variables cfg.ivar and cfg.cvar follows the same logic as for one-factorial designs in Fieldtrip (check out the tutorial http://www.fieldtriptoolbox.org/tutorial/cluster_permutation_timelock and http://www.fieldtriptoolbox.org/faq/how_can_i_use_the_ivar_uvar_wvar_and_cvar_options_to_precisely_control_the_permutations?s[]=design&s[]=matrix).
46+
47+
48+
The Sim_indepANOVA_* files exemplify how to perform exact permutation tests with restricted permutations and approximate tests on either the raw data or the residuals under a reduced model as described in �Permutation tests for multi-factorial analysis of variance. Marti Anderson and Cajo Ter Braak. Journal of Statistical Computation and Simulation Vol. 73, Iss. 2, 2003.
49+
50+
You'll have to run the permutation ANOVA for each effect separately by specifying cfg.fac = 'a', 'b' or 'iaxb'.
51+
52+

0 commit comments

Comments
 (0)