attachment:example_djm_partitions.m of COGNESTIC2023 - Methods
location: attachment:example_djm_partitions.m of COGNESTIC2023

Attachment 'example_djm_partitions.m'

Download

   1 function example_djm_partitions()
   2   %{
   3   %%%%%%%%%%%%%%%%%%%%%
   4   djm: This shows a simple group analysis for the vt mask of the AK6 dataset.
   5   It illustrates three types of partition: single split-half (e.g. oddeven), nfold
   6   (aka leave-one-out), and repeated split-half.
   7   %%%%%%%%%%%%%%%%%%%%%
   8   %}
   9 
  10   %% Define data
  11   config=cosmo_config();
  12   subs={'s01','s02','s03','s04','s05','s06','s07','s08'};
  13   partitions={'odd_even', 'nfold', 'full_split_half'};
  14 
  15   rng(0); % reset random number generator for reproducability
  16 
  17   figure(9); clf(9);
  18 
  19   result=nan( numel(subs), numel(partitions) ); % djm, preallocate array
  20   for s=1:numel(subs)
  21     fprintf('.')
  22     data_path=fullfile(config.tutorial_data_path,'ak6',subs{s});
  23     data_fn=fullfile(data_path,'glm_T_stats_perrun.nii');
  24     mask_fn=fullfile(data_path,'vt_mask.nii');
  25     ds=cosmo_fmri_dataset(data_fn,'mask',mask_fn,...
  26     'targets',repmat(1:6,1,10),... % 6 types of animal
  27     'chunks',floor(((1:60)-1)/6)+1); % 10 runs
  28 
  29     % remove constant features (due to liberal masking)
  30     ds=cosmo_remove_useless_data(ds);
  31 
  32     % Assign a function handle to the cosmo_crossvalidation_measure
  33     measure=@cosmo_crossvalidation_measure;
  34 
  35     % Make a struct containing the arguments for the measure:
  36     args=struct();
  37     args.classifier=@cosmo_classify_nn;
  38 
  39     for p=1:numel(partitions)
  40 
  41       switch partitions{p}
  42         case 'odd_even'
  43           args.partitions=cosmo_oddeven_partitioner(ds,'half');
  44         case 'nfold'
  45           args.partitions=cosmo_nfold_partitioner(ds);
  46         case 'full_split_half'
  47           args.partitions=cosmo_nchoosek_partitioner(ds,0.5);
  48         otherwise
  49           error('unknown partition type')
  50       endswitch
  51       cosmo_check_partitions(args.partitions,ds);
  52 
  53       % Apply the measure to ds, with args as second argument.
  54       tic
  55       ds_accuracy=measure(ds,args);
  56 
  57       % for subject 1, plot partitions, and how long this scheme took
  58       if s==1
  59         subplot(2,2,p)
  60         plot_partitions(args.partitions);
  61         title(sprintf('%s; tooks %.1f s per subject',partitions{p},toc),'interpreter','none')
  62         drawnow
  63       endif
  64 
  65       % store the result as accuracy minus chance (so positve values indicate information present)
  66       result(s,p)=ds_accuracy.samples-1/6;
  67 
  68     end % next partition scheme
  69   end % next subject
  70 
  71   % Run ttest versus chance (now zero)
  72   [h, p, ci, stat]=ttest(result);
  73 
  74   % plot results with 95% confidence intervals
  75   subplot(2,2,4)
  76   errorbar(mean(result),range(ci)./2,'o')
  77   set(gca,'xtick',1:numel(partitions),'xticklabel',partitions)
  78   ylabel('accuracy minus chance')
  79   ylim([-0.2 0.5]);
  80   hold on
  81   plot(xlim,[0 0],'--')
  82   drawnow
  83 
  84   return
  85 
  86   function plot_partitions(partitions)
  87     % djm: plot partitions like in documentation
  88     maxs=max(cellfun(@max,[ partitions.train_indices partitions.test_indices]));
  89     nc=numel( partitions.test_indices);
  90     out=zeros(maxs,nc);
  91     for c=1:nc
  92       out(partitions.train_indices{c},c)=1;
  93       out(partitions.test_indices{c},c)=2;
  94     endfor
  95     imagesc(out);
  96     if nc<21
  97       set(gca,'xtick',1:nc)
  98     else
  99       set(gca,'xtick',[1 nc])
 100     endif
 101     xlabel('classifiers')
 102     ylabel('samples')
 103     colormap([1 1 1; 0 1 0; 1 0 0]);
 104     caxis([0 2])
 105     return

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2023-09-26 08:48:28, 451748.0 KB) [[attachment:02_lecture1_MVPA_intro.mp4]]
  • [get | view] (2023-09-26 08:51:53, 575765.6 KB) [[attachment:03_lecture2_Classification.mp4]]
  • [get | view] (2023-09-26 08:54:43, 414220.2 KB) [[attachment:08_lecture6_RSA.mp4]]
  • [get | view] (2023-09-29 06:24:49, 12159.4 KB) [[attachment:AH_slides.pptx]]
  • [get | view] (2023-09-04 12:15:23, 7769.3 KB) [[attachment:BrainStim_slides.pptx]]
  • [get | view] (2023-09-14 09:27:20, 1684.5 KB) [[attachment:COGNESTIC-23_hands-on_materials.pdf]]
  • [get | view] (2023-09-28 13:07:14, 4645.7 KB) [[attachment:COGNESTIC23-presentation_Sebenius.pdf]]
  • [get | view] (2023-09-27 08:34:11, 11017.1 KB) [[attachment:COGNESTIC23_MVPA_djm_part1.pptx]]
  • [get | view] (2023-09-27 08:34:43, 11433.3 KB) [[attachment:COGNESTIC23_MVPA_djm_part2.pptx]]
  • [get | view] (2023-09-17 12:28:39, 7416.4 KB) [[attachment:COGNESTIC_OpenCogNeuro.pdf]]
  • [get | view] (2023-09-20 20:09:47, 15.6 KB) [[attachment:COGNESTIC_exercises_2023.docx]]
  • [get | view] (2023-09-07 11:34:09, 37.8 KB) [[attachment:CamCAN Data User Agreement_COGNESTIC.docx]]
  • [get | view] (2023-09-20 16:23:31, 26025.7 KB) [[attachment:EEGMEG1-preprocessing.zip]]
  • [get | view] (2023-09-20 16:23:44, 5903.9 KB) [[attachment:EEGMEG2-sourceestimation.zip]]
  • [get | view] (2023-09-20 16:23:53, 4194.2 KB) [[attachment:EEGMEG3-timefrequency.zip]]
  • [get | view] (2023-09-20 16:24:00, 98.5 KB) [[attachment:EEGMEG4-advanced.zip]]
  • [get | view] (2023-09-20 16:24:09, 595.9 KB) [[attachment:EEGMEG5-decoding.zip]]
  • [get | view] (2023-09-25 16:12:16, 2963.2 KB) [[attachment:EMEG1_1_Measurement.pdf]]
  • [get | view] (2023-09-25 16:12:29, 2273.0 KB) [[attachment:EMEG1_2_Preprocessing.pdf]]
  • [get | view] (2023-09-25 16:12:49, 1643.3 KB) [[attachment:EMEG1_3_Averaging.pdf]]
  • [get | view] (2023-09-25 16:13:08, 2483.0 KB) [[attachment:EMEG2_1_ForwardModelling.pdf]]
  • [get | view] (2023-09-25 16:13:24, 2290.3 KB) [[attachment:EMEG2_2_MNE.pdf]]
  • [get | view] (2023-09-25 16:13:34, 2337.0 KB) [[attachment:EMEG2_3_SpatialResolution.pdf]]
  • [get | view] (2023-09-25 16:18:32, 2031.8 KB) [[attachment:EMEG2_4_Decoding.pdf]]
  • [get | view] (2023-09-25 16:32:19, 2227.7 KB) [[attachment:EMEG3_1_TimeFrequency.pdf]]
  • [get | view] (2023-09-25 16:13:58, 6451.2 KB) [[attachment:EMEG3_1_TimeFrequency.pptx]]
  • [get | view] (2023-09-25 16:15:17, 1798.5 KB) [[attachment:EMEG3_2_FunctionalConnectivity.pdf]]
  • [get | view] (2023-09-25 16:14:16, 2695.9 KB) [[attachment:EMEG3_3_AdvancedFunctionalConnectivity.pdf]]
  • [get | view] (2023-09-25 16:18:07, 467.0 KB) [[attachment:EMEG4_1_Stats.pdf]]
  • [get | view] (2023-09-25 16:18:20, 2175.9 KB) [[attachment:EMEG4_2_Multimodal.pdf]]
  • [get | view] (2023-09-28 13:00:51, 2143.2 KB) [[attachment:EMEG5_Decoding.pdf]]
  • [get | view] (2023-09-27 13:53:49, 15308.0 KB) [[attachment:EMEG5_Decoding.pptx]]
  • [get | view] (2023-09-22 09:00:49, 112.6 KB) [[attachment:Exercises_EEGMEG.pdf]]
  • [get | view] (2023-09-20 21:18:39, 1.6 KB) [[attachment:FDT_DTI_TBSS.sh]]
  • [get | view] (2023-09-20 21:18:56, 1.3 KB) [[attachment:FDT_DTI_group_QC.sh]]
  • [get | view] (2023-09-20 21:18:28, 4.1 KB) [[attachment:FDT_DTI_pipeline_LiveDemo.sh]]
  • [get | view] (2023-09-20 09:29:08, 0.9 KB) [[attachment:FSLVBM_cognestic_all.sh]]
  • [get | view] (2023-09-20 09:28:46, 2570.9 KB) [[attachment:FSLVBM_tutorials_2023.docx]]
  • [get | view] (2023-09-20 21:22:42, 1322.5 KB) [[attachment:FSL_DTI&TBSS.pdf]]
  • [get | view] (2023-09-20 21:15:13, 4129.4 KB) [[attachment:FSL_FDT_DTI_tutorials_2023.docx]]
  • [get | view] (2023-09-20 09:28:03, 1341.7 KB) [[attachment:FSL_VBM.pdf]]
  • [get | view] (2023-09-20 20:15:14, 1338.8 KB) [[attachment:FS_CorticalThickness.pdf]]
  • [get | view] (2023-09-20 20:14:28, 1.2 KB) [[attachment:FS_ROI_analysis.sh]]
  • [get | view] (2023-09-20 20:14:13, 0.1 KB) [[attachment:FS_check_location.sh]]
  • [get | view] (2023-09-20 20:14:21, 2.1 KB) [[attachment:FS_group_analysis.sh]]
  • [get | view] (2023-09-20 20:14:35, 0.9 KB) [[attachment:FS_visualising_output.sh]]
  • [get | view] (2023-09-20 20:44:04, 2211.7 KB) [[attachment:FreeSurfer_tutorials_2023.docx]]
  • [get | view] (2023-08-29 09:36:06, 108.5 KB) [[attachment:General EEGMEG Literature.pdf]]
  • [get | view] (2023-09-20 10:46:09, 585.4 KB) [[attachment:Intro_Commmand_Line_2023.docx]]
  • [get | view] (2023-09-07 11:38:14, 1243.5 KB) [[attachment:IntroductionToDiffusionMRI_I.pdf]]
  • [get | view] (2023-09-07 11:39:05, 2336.6 KB) [[attachment:IntroductionToDiffusionMRI_II.pdf]]
  • [get | view] (2023-09-07 11:36:05, 807.9 KB) [[attachment:IntroductionToGLM.pdf]]
  • [get | view] (2023-09-07 11:37:10, 2565.7 KB) [[attachment:IntroductionToMRIPhysics.pdf]]
  • [get | view] (2023-09-22 15:02:29, 1.7 KB) [[attachment:MNE-Python_datasets.ipynb]]
  • [get | view] (2023-09-20 08:40:09, 182.1 KB) [[attachment:MNE_Installation_Instructions.pdf]]
  • [get | view] (2023-09-21 21:13:14, 1046.2 KB) [[attachment:MRTrix_tractography.pdf]]
  • [get | view] (2023-09-21 21:15:15, 3.5 KB) [[attachment:MRtrix_dMRI_CSD_tractography_LiveDemo.sh]]
  • [get | view] (2023-09-21 21:15:06, 0.9 KB) [[attachment:MRtrix_dMRI_connectome_LiveDemo.sh]]
  • [get | view] (2023-09-21 21:15:26, 2.5 KB) [[attachment:MRtrix_dMRI_preprocessing_LiveDemo.sh]]
  • [get | view] (2023-09-21 21:13:32, 6635.8 KB) [[attachment:MRtrix_dMRI_tutorials_2023.docx]]
  • [get | view] (2023-09-29 15:16:34, 4133.1 KB) [[attachment:MacIntyre_COGNESTIC.pdf]]
  • [get | view] (2023-09-07 16:20:09, 1065.6 KB) [[attachment:Multimodal_DCM_cognestic_tutorial_fMRI.pdf]]
  • [get | view] (2023-09-26 13:21:22, 25.3 KB) [[attachment:Notebooks_mne_bids_pipeline.zip]]
  • [get | view] (2023-09-27 08:33:01, 3.2 KB) [[attachment:example_djm_partitions.m]]
  • [get | view] (2023-09-27 08:33:38, 3.3 KB) [[attachment:example_djm_unbalanced.m]]
  • [get | view] (2023-09-26 13:31:29, 924.8 KB) [[attachment:mne-bids-pipeline_cognestic.pdf]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.