-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert_spm_stat.m
61 lines (53 loc) · 1.87 KB
/
convert_spm_stat.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
%
% Usage: convert_spm_stat(conversion, infile, outfile, dof)
%
% This script uses a template .mat batch script object to
% convert an SPM (e.g. SPMT_0001.hdr,img) to a different statistical rep.
% (Requires matlab stats toolbox)
%
% Args:
% conversion -- one of 'TtoZ', 'ZtoT', '-log10PtoZ', 'Zto-log10P',
% 'PtoZ', 'ZtoP'
% infile -- input file stem (may include full path)
% outfile -- output file stem (may include full pasth)
% dof -- degrees of freedom
%
% Created by: Josh Brown
% Modification date: Aug. 3, 2007
% Modified: 8/21/2009 Adam Krawitz - Added '-log10PtoZ' and 'Zto-log10P'
% Modified: 2/10/2010 Adam Krawitz - Added 'PtoZ' and 'ZtoP'
function completed=convert_spm_stat(conversion, infile, outfile, dof)
old_dir = cd();
if strcmp(conversion,'TtoZ')
expval = ['norminv(tcdf(i1,' num2str(dof) '),0,1)'];
elseif strcmp(conversion,'ZtoT')
expval = ['tinv(normcdf(i1,0,1),' num2str(dof) ')'];
elseif strcmp(conversion,'-log10PtoZ')
expval = 'norminv(1-10.^(-i1),0,1)';
elseif strcmp(conversion,'Zto-log10P')
expval = '-log10(1-normcdf(i1,0,1))';
elseif strcmp(conversion,'PtoZ')
expval = 'norminv(1-i1,0,1)';
elseif strcmp(conversion,'ZtoP')
expval = '1-normcdf(i1,0,1)';
else
disp(['Conversion "' conversion '" unrecognized']);
return;
end
if isempty(outfile)
outfile = [infile '_' conversion];
end
if strcmp(conversion,'ZtoT')
expval = ['tinv(normcdf(i1,0,1),' num2str(dof) ')'];
elseif strcmp(conversion,'-log10PtoZ')
expval = 'norminv(1-10.^(-i1),0,1)';
end
%%% Now load into template and run
jobs{1}.util{1}.imcalc.input{1}=[infile '.img,1'];
jobs{1}.util{1}.imcalc.output=[outfile '.img'];
jobs{1}.util{1}.imcalc.expression=expval;
% run it:
spm_jobman('run', jobs);
cd(old_dir)
disp(['Conversion ' conversion ' complete.']);
completed = 1;