-
Notifications
You must be signed in to change notification settings - Fork 28
/
palm_effectiven.m
96 lines (87 loc) · 2.67 KB
/
palm_effectiven.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
function n = palm_effectiven(nP,EE,ISE,islog)
% Given a number of shufflings, compute the effective
% sample size.
%
% Usage:
% n = palm_effectiven(nP,EE,ISE,islog)
%
% Inputs:
% - nP : Number of shufflings (permutations, sign-flippings
% or permutations with sign-flippings).
% - EE : Boolean indicating whether the shufflings include
% permutations (exchangeable errors).
% Default is true.
% - ISE : Boolean indicating whether the shufflings include
% sign-flippings (independent and symmetric errors).
% Default is false.
% - islog : Boolean indicating whether nP is given as log(nP).
% Default is false.
%
% Outputs:
% - n : Effective sample size.
%
% _____________________________________
% Anderson M. Winkler
% FMRIB / University of Oxford
% Oct/2014
% http://brainder.org
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% PALM -- Permutation Analysis of Linear Models
% Copyright (C) 2015 Anderson M. Winkler
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Simple argument parsing
narginchk(1,4);
if nargin == 1,
EE = true;
ISE = false;
islog = false;
elseif nargin == 2,
ISE = false;
islog = false;
elseif nargin == 3,
islog = false;
end
% The Lambert's W function requires the 'specfun' package in Octave.
% For Matlab, it requires the Symbolic Math Toolbox.
if palm_isoctave,
pkg load specfun
end
if EE && ~ISE,
% Permutations only
if islog,
cte = nP - log(sqrt(2*pi));
n = cte./lambertw(cte/exp(1))-.5;
else
cte = log(nP/sqrt(2*pi));
n = cte./lambertw(cte/exp(1))-.5;
end
elseif ~EE && ISE,
% Sign-flippings only
if islog,
n = nP*log2(exp(1));
else
n = log2(nP);
end
elseif EE && ISE,
% Permutations with sign-flippings
if islog,
cte = nP - log(sqrt(pi));
n = cte./lambertw(2*cte/exp(1))-.5;
else
cte = log(nP/sqrt(pi));
n = cte./lambertw(2*cte/exp(1))-.5;
end
end