June 02, 2010

SPM99 Gem 18: –log10 P–values from T images

P-value images are difficult to visualize since "important" values are small and clumped near zero. A -log10 transformation makes for much better visualization while still having interpretability (e.g. a value of 3 cooresponds to P=0.001).

This function,T2nltP, will create -log10 P-value image based on either a contrast number (which must be a T contrast) or a T statistic image and the degrees of freedom.

(See also the equivalent SPM2 function.)

t2nltp.m

function T2nltP(a1,a2)
% Write image of -log10 P-values for a T image
%
% FORMAT T2nltP(c)
% c     Contrast number of a T constrast (assumes cwd is a SPM results dir)
%
% FORMAT T2nltP(Timg,df)
% Timg  Filename of T image
% df    Degrees of freedom
%
%
% As per SPM convention, T images are zero masked, and so zeros will have
% P-value NaN.
%
% @(#)T2nltP.m	1.2 T. Nichols 03/07/15

if nargin==1
  c = a1;
  load xCon
  load SPM xX
  if xCon(c).STAT ~= 'T', error('Not a T contrast'); end
  Tnm = sprintf('spmT_%04d',c);
  df = xX.erdf;
else
  Tnm = a1;
  df  = a2;  
end


Tvol = spm_vol(Tnm);

Pvol        = Tvol;
Pvol.dim(4) = spm_type('float');
Pvol.fname  = strrep(Tvol.fname,'spmT','spm_nltP');
if strcmp(Pvol.fname,Tvol.fname)
  Pvol.fname = fullfile(spm_str_manip(Tvol.fname,'H'), ...
			['nltP' spm_str_manip(Tvol.fname,'t')]);
end


Pvol = spm_create_image(Pvol);

for i=1:Pvol.dim(3),
  img         = spm_slice_vol(Tvol,spm_matrix([0 0 i]),Tvol.dim(1:2),0);
  img(img==0) = NaN;
  tmp         = find(isfinite(img));
  if ~isempty(tmp)
    img(tmp)  = -log10(max(eps,1-spm_Tcdf(img(tmp),df)));
  end
  Pvol        = spm_write_plane(Pvol,img,i);
end;



- No comments


Add a comment

Name
Email
Anti-Spam Question
My t-shirt is red. What colour is my t-shirt?
Anti-Spam Answer
Comment


Your IP address will be recorded. -

You can not use HTML, but you can use our special markup -

Search this blog

Tags

Most recent comments

  • Hi, Folks, conversion to HTML still works for PPT 2011 under OS 10.10 (as on my computer), with coup… by Andrew Fisher on this entry
  • HTML pages are different from PPT. It is possible to convert PPT in HTML page but it will create a p… by Ramjas on this entry
  • Hi This doesn't really address the issue at hand (powerpoint to html), but an alternative and very e… by Rose on this entry
  • @Michael. You are a SAINT. BLESS. by emma riley on this entry
  • I look this up every couple of years, and always struggle with it, so here are some notes for improv… by johann beda on this entry

Blog archive

Loading…
Not signed in
Sign in

Powered by BlogBuilder
© MMXIX