-
Notifications
You must be signed in to change notification settings - Fork 28
/
palm_qtof.m
94 lines (88 loc) · 2.93 KB
/
palm_qtof.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
function [F,Fdf1,Fdf2] = palm_qtof(Q,df1,df2,p,Qname)
% Convert a multivariate MANOVA/MANCOVA scalar
% statistic (Q) to an F-score. The conversion is only
% approximate for most methods and cases.
%
% Usage:
% [F,Fdf1,Fdf2] = palm_qtof(Q,df1,df2,p,Qname)
%
% Inputs:
% - Q : Q-statistic.
% - df1 : Degrees of freedom of the model. This is typically
% the rank of the contrast, rank(C).
% - df2 : Degrees of freedom of the error. This is typically
% N-rank(M).
% - p : Number of dependent variables in the model. This is
% typically rank(Y) or rank(D).
% - Qname : Name of the stastistic. It can be one of:
% 'Wilks', 'Pillai', 'Hotelling' or 'Roy_ii'.
%
% Outputs:
% - F : F-statistic (often approximate).
% - Fdf1 : Degrees of freedom of the hypothesis.
% - Fdf2 : Degrees of freedom of the error.
%
% _____________________________________
% Anderson Winkler
% FMRIB / University of Oxford
% Mar/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/>.
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
switch lower(Qname),
case 'wilks',
r = df2-(p-df1+1)/2;
u = (p*df1-2)/4;
cden = (p^2+df1^2-5);
if cden > 0,
t = sqrt((p^2*df1^2-4)/cden);
else
t = 1;
end
F = (r*t-2*u)*(1-Q.^(1/t))./(Q.^(1/t)*p*df1);
Fdf1 = p*df1;
Fdf2 = r*t-2*u;
case 'pillai',
m = (abs(p-df1)-1)/2;
n = (df2-p-1)/2;
s = min(p,df1);
F = (2*n+s+1)/(2*m+s+1)*(Q./(s-Q));
Fdf1 = s*(2*m+s+1);
Fdf2 = s*(2*n+s+1);
case 'hotelling',
m = (abs(p-df1)-1)/2;
n = (df2-p-1)/2;
s = min(p,df1);
if n > 0,
b = (p+2*n)*(df1+2*n)/(2*(2*n+1)*(n-1));
c = (2+(p*df1+2)/(b-1))/(2*n);
Fdf1 = p*df1;
Fdf2 = 4+(p*df1+2)/(b-1);
F = (Q/c)*Fdf2/Fdf1;
else
Fdf1 = s*(2*m+s+1);
Fdf2 = 2*(s*n+1);
F = (Q/s)*Fdf2/Fdf1;
end
case 'roy_ii',
Fdf1 = max(p,df1);
Fdf2 = df2-Fdf1+df1;
F = Q*Fdf2/Fdf1;
otherwise
error('Statistic %s unknown.',Qname);
end