-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathExample_2way_indepANOVA.m
executable file
·94 lines (75 loc) · 3.22 KB
/
Example_2way_indepANOVA.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
stemFolder = pwd;
load([stemFolder filesep 'dummy'],'data');
cfg_neighb = [];
cfg_neighb.method = 'template';
cfg_neighb.template = 'CTF275_neighb.mat';
neighbours = ft_prepare_neighbours(cfg_neighb, data);
%% Gender-Dosage test data set
% Test data set from: http://personality-project.org/r/r.guide/r.anova.html
% Indep 2x2 ANOVA: factors Gender & dosage on alertness level
% Design matrix for the test data
design(1,:) = [ones(1,2*4) ones(1,2*4)*2]; % First factor: Gender
design(2,:) = repmat([ones(1,4) ones(1,4)*2],1,2); % Second Factor: Dosage
data.powspctrm = [8 12 13 12 6 7 23 14 15 12 22 14 15 12 18 22]';
% Results given at the personality-project.org page
% Df Sum Sq Mean Sq F value Pr(>F)
% Gender 1 76.562 76.562 2.9518 0.1115
% Dosage 1 5.062 5.062 0.1952 0.6665
% Gender:Dosage 1 0.063 0.063 0.0024 0.9617
% Residuals 12 311.250 25.938
%% Specify configuration structure: the dummy data structure consists of a single channel, time bin and frequency of interest
cfg = [];
cfg.channel = {'MLC11'};
cfg.latency = [1 1];
cfg.frequency = [4 4];
cfg.avgovertime = 'no';
cfg.avgoverfreq = 'no';
cfg.avgoverchan = 'no';
cfg.method = 'montecarlo';
cfg.correctm = 'cluster';
cfg.clusteralpha = 1; % consider all clusters irrespectively of significance
cfg.clusterstatistic = 'maxsum';
cfg.minnbchan = 0; % we are looking at one channel only
cfg.statistic = 'indepAnova2way';
cfg.fac = 'iaxb'; % main effect Gender: 'a', main effect Dosage: 'b' and interaction: 'iaxb'
cfg.tail = 1; % F-values can only take positive values
cfg.clustertail = 1;
cfg.design = design;
cfg.neighbours = neighbours;
cfg.numrandomization = 999; % number of permutations
%% define permutation strategies
main_exact_flag = 'yes';
switch cfg.fac
case 'a'
switch main_exact_flag
case 'no' % unrestricted permutations across levels of both factors
cfg.ivar = [1 2];
cfg.wvar = [];
cfg.uvar = [];
cfg.cvar = [];
case 'yes' % restricted permutations within levels of the other factor (exact test)
cfg.ivar = [1 2];
cfg.wvar = [];
cfg.uvar = [];
cfg.cvar = 2;
end
case 'b'
switch main_exact_flag
case 'no'
cfg.ivar = [1 2];
cfg.wvar = [];
cfg.uvar = [];
cfg.cvar = [];
case 'yes'
cfg.ivar = [1 2];
cfg.wvar = [];
cfg.uvar = [];
cfg.cvar = 1;
end
case 'iaxb' % unrestricted permutations across levels of both factors
cfg.ivar = [1 2];
cfg.wvar = [];
cfg.uvar = [];
cfg.cvar = [];
end
stat = ft_freqstatistics(cfg, data);