Creating masks with voxels' p<0.0001 in AFNI

Hi everyone, here I have a question of AFNI.

I want to create some masks in AFNI. In the GUI, using the coef sub-brick as overlay and the t stat map as threshold, it will display which voxels are significantly above a certain threshold (like p<0.0001).

My question is what command should I use to extract these voxels into a mask? I know 3dcalc -a XXX -expr 'ispositive(a - certain values)' can do the job of extracting voxels greater than certain values. But what if I want to make the 'values' here some p-values?

Thanks for your help :slight_smile:

Howdy-

A couple of options for navigating this.

First, I see you have a T-stat, but you are only looking at positive values. Some software promote the use to using two, 1-sided thresholds to extra information, but that can lead to mathematical malfeasance if users aren't careful and wary. Please see this article for more info on properly analyzing 2-sided tests (which a T-test nearly always is):

To do the mechanics of you what you want, you can see the value and useful stat info out on the command line, with p2dsetstat and using either the subbrick label of the stat or the subbrick number:

p2dsetstat                                       \
     -inset STAT_DSET"[Face-Fixation_GLT#0_Tstat]"      \
     -pval 0.0001                                 \
     -2sided

Note: you must choose to translate 2sidedly or 1sidedly, and again the above paper describes more about this. For T-tests, it is nearly always 2-sidedly that is correct (and pairs of 1-sided testing needs to be adjusted properly, which many people do not do). If I run something like the above on the AFNI_data6 teaching example output, the output would look like:

p2dsetstat -inset stats.FT+tlrc.'[8]' -pval 0.0001 -2sided 
++ Found input file  : stats.FT+tlrc.[8]
++ Subbrick label    : V-A_GLT#0_Tstat
++ p-value           : 0.00010000
++ stat type and par : Ttest(412)
++ sidedness         : 2sided
++ Final stat val    : 3.929022

If you add the -quiet option to the above, then you can get just the number of interest out, the "Final stat val"; that is more useful for scripting. You can save that to a variable, and then use that in a 3dcalc command to create a mask of both the positive and negative sides:

#!/bin/tcsh 

set stat_val = `p2dsetstat                                       \
                  -inset STAT_DSET"[Face-Fixation_GLT#0_Tstat]"  \
                  -pval 0.0001                                   \
                  -2sided                                        \
                  -quiet`

# map where 1 means T>stat_val and -1 means T<-stat_val
3dcalc \
     -a STAT_DSET"[Face-Fixation_GLT#0_Tstat]"  \
     -expr "ispositive(a-${stat_val}) - ispositive(-${stat_val}-a)" \
     -prefix MAP_PLUS_MINUS.nii.gz

# map of stat vals where T>stat_val or T<-stat_val
3dcalc \
     -a STAT_DSET"[Face-Fixation_GLT#0_Tstat]"  \
     -expr "a*ispositive(a-${stat_val}) +a*ispositive(-${stat_val}-a)" \
     -prefix MAP_EXTRACTED_STAT.nii.gz

# map of coef vals where T>stat_val or T<-stat_val
3dcalc \
     -a STAT_DSET"[Face-Fixation_GLT#0_Tstat]"  \
     -b STAT_DSET"[Face-Fixation_GLT#0_Coef]"  \
     -expr "b*ispositive(a-${stat_val}) +b*ispositive(-${stat_val}-a)" \
     -prefix MAP_EXTRACTED_COEF.nii.gz

Note about extracting just the statistic values: this leaves out important information of the estimated effect size, esp. if you are processing with afni_proc.py's recommend scale block. More about this is contained in this paper:

You could also use 3dClusterize for this purpose, setting the minimum clustersize to 1 if you want everything out: -clust_nvox 1.

On a final note, and kudos if you have kept reading this looong reply, there is still valuable information below the threshold. We make the case about why this is so important---avoiding mathematical, statistical, biological and interpretational woe, as demonstrated using the NARPS dataset---here:

--pt

1 Like

Hi, pt!
Thanks for your quick and informative reply :smiley:

I have a question about whether using only positive values.

I was making masks for face processing ROIs, using voxels showing greater response to faces than baseline (fixation here). So at first I thought using only positive values was ok. But a second thought of your reply strikes me, that the face processing ROIs may be made up of voxels working collectively (i.e. some are activated and the others are suppressed). Is this logic correct for applying 2-sided ttests here?

Hi-

I will mention again that this draft, cited above, discusses this in more detail and should be checked out:
A tail of two sides: Artificially doubled false positive rates in neuroimaging due to the sidedness choice with t-tests - PubMed

In the vast majority of cases when studying general linear tests that are contrasts (condition A vs B), most researchers a priori are looking at differences, which is a two sided comparison: A-B>0 and B-A>0, which can also be written B != A. In such cases, one should stick with 2-sided testing and conversions. In cases where there is really only ever the intention of looking at 1 sided of the tests, because of a priori knowledge, etc., then a 1-sided test is suitable. However, that is by far the minority of cases. Several other software don't tend to have 2-sided conversions, though I don't know why, and it appears like many people look at A>B with p=0.001 and B>A with p=0.001, and then report both results claiming overall p=0.001 still, when it is actually p=0.002, which is a doubled false positive rate---and as shown in the above article, when ignoring this and doing clusterwise correction, the FPR error is even higher. This is suprising to me, given the amount of important people in the field often put on the holy threshold of p=0.001.

... which brings me to the other point that the transparent thresholding is probably a more important consideration for overall interpretation and evaluation of results. But if one is going to show results at a purported threshold, it might as well be correct.

--pt

1 Like

Thanks again, pt.

I'm sure to check the articles you mentioned.

Cheers :wink:

Cool, and that reminds me that some of this is also covered in this AFNI Academy playlist on Results Reporting, which might be of interest.

--pt