-
Notifications
You must be signed in to change notification settings - Fork 28
/
palm_gcdf.m
84 lines (73 loc) · 2.41 KB
/
palm_gcdf.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
function gcdf = palm_gcdf(G,df1,df2)
% Convert a pivotal statistic computed with 'pivotal.m'
% (or simplifications) to a parametric p-value.
% The output is 1-p, i.e. the CDF.
%
% Usage:
% cdf = palm_gcdf(G,df1,df2)
%
% Inputs:
% G : G or Z statistic.
% df1, df2 : Degrees of freedom (non infinite).
% df1 must be a scalar
% For z, use df1 = 0.
% For Chi2, use df1 = -1, and df2 as the df.
%
% Outputs:
% cdf : Parametric cdf (1-p), based on a
% t, F, z or Chi2 distribution.
%
% _____________________________________
% Anderson Winkler
% FMRIB / University of Oxford
% Aug/2013
% 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/>.
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Note that for speed, there's no argument checking,
% and some lines are repeated inside the conditions.
if df1 > 1
% G or F
df2 = bsxfun(@times,ones(size(G)),df2);
B = (df1.*G./df2)./(1+df1.*G./df2);
gcdf = betainc(B,df1/2,df2/2);
elseif df1 == 1
% Student's t, Aspin's v
df2 = bsxfun(@times,ones(size(G)),df2);
ic = df2 == 1;
in = df2 > 1e7;
ig = ~(ic|in);
gcdf = zeros(size(G));
if any(ig(:))
gcdf(ig) = betainc(real(1./(1+G(ig).^2./df2(ig))),df2(ig)/2,.5)/2;
end
ig = G > 0 & ig;
gcdf(ig) = 1 - gcdf(ig);
if any(ic(:))
gcdf(ic) = .5 + atan(G(ic))/pi;
end
if any(in(:))
gcdf(in) = erfc(-G(in)/sqrt(2))/2;
end
elseif df1 == 0
% Normal distribution
gcdf = erfc(-G/sqrt(2))/2;
elseif df1 < 0
% Chi^2, via lower Gamma incomplete for precision and speed
gcdf = palm_gammainc(G/2,df2/2,'lower');
end