NAN values in mean FA connectome

Hi guys!
I wanna do structural connectivity analysis so, I calculated the mean length, number of streamlines, and mean FA connectome for my subjects through the following commands.
everything was fine in mean length and streamlines count matrices but I’ve gotten some NAN values in the mean FA connectivity matrix.
The commands I’ve used are:

  1. dwi2tensor dwireged_preproc.mif tensor.mif
  2. tensor2metric tensor.mif -fa FA.mif
  3. tcksample sift_10mio_norm.tck FA.mif mean_FA_per_streamline.csv -stat_tck mean
  4. tck2connectome -symmetric -zero_diagonal sift_10mio_norm.tck aal116.nii.gz connectivity_matrix_mean_FA.csv -scale_file mean_FA_per_streamline.csv -stat_edge mean

actually, I wanna know what is the problem, and as I want to use these matrices for graph-theory-based structural connectivity analysis how I can interpret the NAN values and is it ok to change the NAN values to zero manually or not?
thanks in advance.

Hi Fateme,

If computing the mean value contributed across those streamlines ascribed to each edge, but for a particular edge there were no streamlines ascribed, then this calculation will intrinsically result in a division by zero, hence the NaN values. I prefer it that way. Across the gamut of all possible ways in which a connectome matrix could be calculated, some may require the ability to distinguish between an absence of streamlines, and the presence of streamlines but with a mean value of zero. The “mean FA” of an absent connection is undefined, which the NaNs best communicate.

If any particular downstream analysis of such data is incompatible with the presence of non-finite values, but would instead process the data “appropriately” if such elements contained the value zero, then obviously that’s something you can do yourself manually. However it’s important to recognise that that’s a data manipulation decision on your part, not something intrinsic to either the data or the brain, and that the influence that such a decision will have depends on the particulars of how the data are being operated on (e.g. if some hypothetical graph-theoretical analysis did itself treat NaN vs. 0.0 differently, there would be a reason for such, and that would be something you would want to know about).


Hi @rsmith,

The behavior you describe in tck2connectome when it was introduced? I did some FA weighted connectomes and I observed 0 where the number of streamlines was 0.

In this case, I would have said that some voxel (or voxels) in the FA were NaN. Is this possible?

Best regards,


1 Like

Ah, indeed your memory is better than mine. I found this commit, which goes all the way back to version 3.0_RC1, that addressed the division-by-zero. Indeed the current code does still prevent the divide-by-zero, which’ll teach me for writing a response without checking the code first.

So you’re right, it is indeed more likely that image FA.mif contains some NaN values, which are being picked up by tcksample giving some streamlines NaN “mean FA” values, which then make their way into the connectome. You could find where such voxels are with something like:

mrcalc 1 FA.mif -finite -sub - | mrview FA.mif -roi.load -


Thanks, @mblesac, and @rsmith for your exact answers.
so, isn’t any way to prevent achieving the NaN values in the FA connectome because of tcksample step?

isn’t any way to prevent achieving the NaN values in the FA connectome because of tcksample step?

There isn’t any way to instruct tcksample to ignore NaN values during its computation. You can however replace those voxels with the value 0 prior to it being used in tcksample:

mrcalc FA.mif -finite FA.mif 0.0 -if - | tcksample sift_10mio_norm.tck - mean_FA_per_streamline.csv -stat_tck mean


1 Like

Thanks, Rob, that worked great for me.