Re: How to prepare dataset for group analysis

192 views
Skip to first unread message

raffaele tucciarelli

unread,
Apr 21, 2021, 8:04:28 AM4/21/21
to Rui, CoSMoMVPA
Dear Rui, 

I understand how to run those functions but would these functions use the dataset read by "cosmo_fmri_dataset" , not the nii file itself?
if I understand correctly your question, you first have to read the nifti files in cosmo using cosmo_fmri_dataset, so you have one cosmo structure for each participant, and then combine these datasets into a unique cosmo structure using cosmo_stack (and if necessary, cosmo_mask_dim_intersect), that requires a cell array (each cell array is a participant). Once you have the unique dataset, you can run the group analysis (using appropriate values in .sa.chunks and .sa.targets, see the help of cosmo_montecarlo_cluster_stat). 

Does this answer your question?

Cheers
Raffaele


Il giorno mer 21 apr 2021 alle ore 11:54 Rui <usogah...@gmail.com> ha scritto:
Dear experts,

I am new to CoSMoMVPA and have completed RSA searchlight analyses at each participant level based on many useful examples and this group discussion.
But, I am not sure how can I prepare the dataset for group analysis.
If my understanding is correct, I think I should stack the data came from first analyses (e.g., sub1_RSM.nii, sub2_RSM.nii....) . 
When reading many examples and Q&A, I think I should use "cosm_stack" and, if necessary, "cosmo_mask_dim_intersect". 
I understand how to run those functions but would these functions use the dataset read by "cosmo_fmri_dataset" , not the nii file itself?
How can I adjust the results(i.e., the nii files) that came from first-level analyses?
It may be a basic question but I really appreciate any advice that you have

--
You received this message because you are subscribed to the Google Groups "CoSMoMVPA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cosmomvpa+...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/cosmomvpa/6256c4d5-d507-4976-92eb-dbd122ac39e7n%40googlegroups.com.
Message has been deleted

Rui

unread,
Apr 21, 2021, 10:52:54 AM4/21/21
to CoSMoMVPA
Dear Raffaele

Thanks a lot for your quick reply.
I understand that "cosmo_fmri_dataset" can also read even just the nifti files. 
After stacking the dataset(the nifti files), I think I should use cosmo_map2fmri (i.e., stack_nifti = cosmo_map2fmri (ds_stack,'nii')) to return the nifti file. 
Is it correct?

I have one more question about the whole brain mask file in dataset for group analysis.
Which mask should I use?
Should I also stack all of the participants' binary mask files?

I would be happy if you could give me some advices again.

Best
Rui

2021年4月21日水曜日 21:04:28 UTC+9 rtucci...@gmail.com:

raffaele tucciarelli

unread,
Apr 21, 2021, 12:05:37 PM4/21/21
to Rui, CoSMoMVPA
After stacking the dataset(the nifti files), I think I should use cosmo_map2fmri (i.e., stack_nifti = cosmo_map2fmri (ds_stack,'nii')) to return the nifti file. Is it correct?
No, you do not need to do that, you can work directly with the ds_stack for doing the statistical analysis, so you will get a statistical map and then you can use the cosmo_map2fmri to write the nifti file of the resulting map. 
So, take the example in the cosmo_montecarlo_cluster_stat function

% Example:
%     % Generate tiny synthetic dataset representing 6 subjects, one
%     % condition, 6 voxels
%     ds=cosmo_synthetic_dataset('ntargets',1,'nchunks',6);
%     %
%     % Define clustering neighborhood
%     nh=cosmo_cluster_neighborhood(ds,'progress',false);
%     %
%     % Set options for monte carlo based clustering statistic
%     opt=struct();
%     opt.cluster_stat='tfce';  % Threshold-Free Cluster Enhancement;
%                               % this is a (very reasonable) default
%     opt.niter=50;             % this is way too small except for testing;
%                               % should usually be >=1000;
%                               % better is >=10,000
%     opt.h0_mean=0;            % test against mean of zero
%     opt.seed=1;               % should usually not be used, unless exact
%                               % replication of results is required
%                               %  replication
%     opt.progress=false;       % do not show progress
%                               % (only for in this example)
%     %
%     % Apply cluster-based correction
%     z_ds=cosmo_montecarlo_cluster_stat(ds,nh,opt);

instead of ds, your variable would ds_stack (which is a cosmo structure, in this case, it will have 6 subjects). The resulting map (z_ds), which is still in cosmo structure, can be mapped into a nifti file using cosmo_map2fmri.
  cosmo_map2fmri(z_ds, 'zmap.nii')

Does it make sense?



I have one more question about the whole brain mask file in dataset for group analysis.
Which mask should I use?
Should I also stack all of the participants' binary mask files?
I think there are different options, but if you use the function cosmo_mask_dim_intersect, you don't need to stack the binary mask files, as the function will use directly the common features of all brains. If you follow the example of the cosmo_mask_dim_intersect function, it is quite clear, but let us know if it is not. 

Another option is to have a common mask, so you could stack all binary mask files and select only those voxels that are common to all brains. 

Probably there are other better ways, maybe Nick can suggest something else.

Hope this helps!
Raffaele
 

Rui

unread,
Apr 22, 2021, 4:54:45 AM4/22/21
to CoSMoMVPA
Dear Raffaele

I deeply appreciate your thorough support!
I could stack the nifti files and add the other information, such as "targets" and "chunks", and prepared the dataset for cosmo_montecarlo_cluster_stat .
Although your example code completely run with the sample data, my own data including three participants' data as the test returned the error message.
I read the explanation in cosmo_check_neighborhood and cosmo_cluster_neighborhood, but I could not work this out.
I am sorry to bother you again but would you mind giving me a hint?
 
The error messages are as follows,

error: cosmo_check_neighborhood (line 69)
check_origin_matches: .a.fdim 'values' value mismatch between dataset and neighborhood

error: cosmo_montecarlo_cluster_stat>check_inputs (line 858)
    cosmo_check_neighborhood(nbrhood,ds);

error: cosmo_montecarlo_cluster_stat (line 254)
    check_inputs(ds,nbrhood);


When it comes to mask, I understand that it' OK if the voxel size of samples are common among each participant's data.

Best 
Rui

2021年4月22日木曜日 1:05:37 UTC+9 rtucci...@gmail.com:

raffaele tucciarelli

unread,
Apr 22, 2021, 7:39:34 AM4/22/21
to Rui, CoSMoMVPA
Hi Rui, 

are they in the same brain space (e.g. MNI)? You can stack them only if they have been resampled to a common space

Cheers
Raffaele

Rui

unread,
Apr 22, 2021, 10:47:13 AM4/22/21
to CoSMoMVPA
Dear Raffaele


Thank you for the quick reply!
Yes, they are in the same brain space (i.e., MNI space).
But, I recognize that the point  I should go over is when I stacked the data.
After checking it, I'll ask you again. 

Sincerely, 
Rui




2021年4月22日木曜日 20:39:34 UTC+9 rtucci...@gmail.com:

Rui

unread,
Apr 22, 2021, 8:11:01 PM4/22/21
to CoSMoMVPA
Dear Raffaele

Your code was successful for my data as well!
I'm sorry that there had been a careless mistake in my data.
I really appreciate your help!

Best 
Rui


2021年4月22日木曜日 23:47:13 UTC+9 Rui:

raffaele tucciarelli

unread,
Apr 23, 2021, 8:49:26 AM4/23/21
to Rui, CoSMoMVPA
happy to hear that!
Good luck with the rest of the analysis



Rui

unread,
Apr 27, 2021, 9:32:44 AM4/27/21
to CoSMoMVPA
Hi,  Rafaele

After the group analysis, I'm trying to get the cluster size of each significant cluster.
But, is it impossible for now to get it based on the previous post of this forum?
"Currently there is no functionality to directly output a critical cluster size, although such sizes are computed internally."
But, I found some articles which reported the cluster sizes of the significant clusters, analyzed by CoSMoMVPA.
Would they have used other software (e.g, SPM or AFNI)?

I would be grateful if you could give me a comment.

Best,
Rui



2021年4月23日金曜日 21:49:26 UTC+9 rtucci...@gmail.com:

raffaele tucciarelli

unread,
Apr 28, 2021, 5:42:11 AM4/28/21
to Rui, CoSMoMVPA
Hi Rui, 


Something like this (very crude code, probably needs improvements)


% get your masked map
% it should have only zeros and ones (for voxels that survived staistical test)
ds = cosmo_fmri_dataset('spmT_0010_masked.nii');

% get neighbors for each voxels
nh=cosmo_cluster_neighborhood(ds_masked);

% convert to matrix (for cosmo_clusterize)
nh_mat=cosmo_convert_neighborhood(nh,'matrix');

% find clusters
cl=cosmo_clusterize(ds_masked.samples,nh_mat);

% number of clusters
ncl = length(cl);

% get size of each cluster and sort them
[ncl_sorted, ind_sorted] = sort(cellfun(@numel, cl), 'desc');

% plot cluster size
figure; bar(ncl_sorted);ylabel('# Voxels');xlabel('Clusters');

% order clusters
cl = cl(ind_sorted);



  cosmo_clusterize returns as many cells as clusters, and each cell has the indices associated with that cluster, so you can also get the values from  your unmasked map

% get the values of the biggest cluster
ds_unmasked(cl{1})

Does this help you? Is this what you needed?

I hope it is clear and it will work. If it is not correct, I am sure Nick will notice it :)

Cheers
Raffa

Virus-free. www.avg.com


Virus-free. www.avg.com

Rui

unread,
Apr 28, 2021, 11:31:49 PM4/28/21
to CoSMoMVPA
Hi Raffaele,

Thank you so much!
This is the one I wanted to know. 
This code has just made my concern clear. I deeply appreciate your careful support.
Maybe, all I have to do is to analyze the all data and write the paper...

Best,
Rui


2021年4月28日水曜日 18:42:11 UTC+9 rtucci...@gmail.com:

Nick Oosterhof

unread,
Apr 30, 2021, 9:27:38 AM4/30/21
to Rui, CoSMoMVPA
Hi Rui,

- "Currently there is no functionality to directly output a critical cluster size". Note that critical cluster size is different from actual observed cluster size. The former is how big a cluster should be to survive multiple comparison correction, the latter how big a cluster is. Also, cluster size is a good term when using a fixed uncorrected threshold (which is a researcher's degree of freedom; different values may lead to different results). TFCE may be preferable, because it lacks such a degree of freedom; but for TFCE "cluster size" is not the best description, rather each feature (voxel) gets a TFCE score. 

- the code that Raffaele shared looks good (thanks Raffaele!), though be careful not to accidentally use other input data (such as a T map). You could also use the output from cosmo_montecarlo_cluster_stat directly, where you would apply a mask in order to select only features (voxels) that survive a (corrected) z-score threshold.  

best,
Nick


Reply all
Reply to author
Forward
0 new messages