Skip to content

noise_prec_from_unbalanced produces NaN values  #389

Description

@ndolf

Hello,

I recently started using rsatoolbox in python in order to compute Mahalanobis distances (and eventually crossnobis + taking noise variance into account). I have an unbalanced design - the number of voxels/channels differs between conditions and I am not sure how the toolbox is dealing with these NaN values when computing the precision matrix.

I have 8 different conditions (or items) and 4 runs, resulting in 32 patterns (Each condition was repeated once in every run). The number of channels differ between conditions (or even within conditions across runs) - when a value is missing this is replaced by a NaN value

            measurements = measurements['activation_patterns']
            nItems = 8
            n_rep = measurements.shape[0]/nItems;
            nCond = measurements.shape[0]/n_rep;       
            nVox = measurements.shape[1];
            
            items = np.array(['stim_%02d' % x for x in np.arange(nCond)])
            items = np.repeat(items, n_rep)
            runs = np.tile(np.arange(n_rep), nItems)
            
            # now create a  dataset object
            des = {'Task': task, 'subj': sub, 'ROI': roi_counter+1}
            obs_des = {'items': items, 'runs': runs}
            chn_des = {'voxels': np.array(['voxel_' + str(x) for x in np.arange(1,nVox+1)])}           
         
            data=rsd.Dataset(measurements=measurements,
                                       descriptors=des,
                                       obs_descriptors=obs_des,
                                       channel_descriptors=chn_des)

I wanted to start simple and follow the demo to compute the precision matrix:
noise_prec_diag = rsatoolbox.data.noise.prec_from_measurements(data, obs_desc='items', method='diag')

as this gave me a noise precision matrix with NAN values I tried:

         noise_prec_diag = rsatoolbox.data.noise.prec_from_unbalanced(data, obs_desc='items', method='diag')

Again I get all NaN values in the noise precision matrix and I noticed when looking at data.measurements that running this function sets all the rows of any channel that had missing values to NaN (so now the channel has NaN values for all conditions and runs, while initially it only had NaN for certain rows).

I tried to figure it out by looking at the code of the toolbox but it is really hard to follow the order of computations.

I have two questions:

  • The precision matrix has 1 variance per voxel, so this means that the variance for each voxel is computed across all conditions and runs. Is this how I am supposed to do it?
  • Why do I get NaN in the output of the precision estimation? Does it not deal with missing data (even though it is the function for unbalanced designs)?

Irrespective of the issue with the NAN values I was also doubting whether 8 conditions x 4 runs is enough to estimate precision. I have residuals (1 per voxel) from the GLM that potentially could be used instead but I was not sure it is ok to just have 1 residual per voxel (even though I have 32 multivoxel patterns = 8 conditions x 4 runs).

Thank you in advance for any help!

Nina

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions