-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRSA_sample_script.m
More file actions
100 lines (78 loc) · 4.73 KB
/
RSA_sample_script.m
File metadata and controls
100 lines (78 loc) · 4.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
% This script is a template that can be used for a representational
% similarity analysis on brain image data. It is for people who have betas
% available from an SPM.mat and want to automatically extract the relevant
% images used for the similarity analysis, as well as corresponding labels
% and decoding chunk numbers (e.g. run numbers). If you don't have this
% available, then inspect the differences between decoding_template and
% decoding_template_nobetas and adapt this template to use it without
% betas.
% Set defaults
cfg = decoding_defaults;
% Set the analysis that should be performed (default is 'searchlight')
cfg.analysis = 'ROI'; %'searchlight'
% Set the output directory where data will be saved, e.g. 'c:\exp\results\buttonpress'
cfg.results.dir = '/Volumes/hermes/tdt_tutorial/sub01_firstlevel/sub01_results/';
% Set the filepath where your SPM.mat and all related betas are, e.g. 'c:\exp\glm\model_button'
beta_loc = '/Volumes/hermes/tdt_tutorial/sub01_firstlevel/sub01_GLM/';
% Set the filename of your brain mask (or your ROI masks as cell matrix)
% for searchlight or wholebrain e.g. 'c:\exp\glm\model_button\mask.img' OR
% for ROI e.g. {'c:\exp\roi\roimaskleft.img', 'c:\exp\roi\roimaskright.img'}
% You can also use a mask file with multiple masks inside that are
% separated by different integer values (a "multi-mask")
cfg.files.mask = '/Volumes/hermes/tdt_tutorial/sub01_firstlevel/sub01_ROI/m1_left.img';
% Set the label names to the regressor names which you want to use for
% your similarity analysis, e.g.
% labelnames = {'stim 1', 'stim 2', etc.};
% Labels typically are arbitrary and can be set as described below.
% If you want to use all betas that are not nuisance regressors or
% constants, just set
labelnames = [];
% since the labels are arbitrary, we will set them randomly to -1 and 1
labels(1:2:length(labelnames)) = -1;
labels(2:2:length(labelnames)) = 1;
% set everything to similarity analysis (for available options as model parameters, check decoding_software/pattern_similarity/pattern_similarity.m)
cfg.decoding.software = 'similarity';
cfg.decoding.method = 'classification';
cfg.decoding.train.classification.model_parameters = 'pearson'; % this is pearson correlation
% Beware: This option just passes the similarity matrices. This can produce
% a lot of data. (one matrix per voxel for searchlight analyses). In that
% case, consider using another output measure (such as a similarity matrix
% to compare the results to)
% There are two outputs that may make sense: Use 'other' if you want one
% similarity estimate per condition per run, and use 'other_average' if you
% want to average betas across runs before calculating the similarity.
cfg.results.output = 'other';
% Set additional parameters manually if you want (see decoding.m or
% decoding_defaults.m). Below some example parameters that you might want
% to use:
% cfg.searchlight.unit = 'mm';
% cfg.searchlight.radius = 12; % this will yield a searchlight radius of 12mm.
% cfg.searchlight.spherical = 1;
% cfg.verbose = 2; % you want all information to be printed on screen
% cfg.decoding.train.classification.model_parameters = '-s 0 -t 0 -c 1 -b 0 -q';
% cfg.results.output = {'accuracy_minus_chance','AUC_minus_chance'};
% Some other cool stuff
% Check out
% combine_designs(cfg, cfg2)
% if you like to combine multiple designs in one cfg.
% Enable scaling min0max1 (otherwise libsvm can get VERY slow)
% if you dont need model parameters, and if you use libsvm, use:
cfg.scale.method = 'min0max1';
cfg.scale.estimation = 'all'; % scaling across all data is equivalent to no scaling (i.e. will yield the same results), it only changes the data range which allows libsvm to compute faster
% Decide whether you want to see the searchlight/ROI/... during decoding
cfg.plot_selected_voxels = 0; % 0: no plotting, 1: every step, 2: every second step, 100: every hundredth step...
% Add additional output measures if you like
% cfg.results.output = {'accuracy_minus_chance', 'AUC'}
%% Nothing needs to be changed below for a standard similarity analysis using all data
% The following function extracts all beta names and corresponding run
% numbers from the SPM.mat
regressor_names = design_from_spm(beta_loc);
% Extract all information for the cfg.files structure (labels will be [1 -1] )
cfg = decoding_describe_data(cfg,labelnames,labels,regressor_names,beta_loc);
% This creates a design in which all data is used to calculate the similarity
cfg.design = make_design_similarity(cfg);
% Use the next line to use RSA with cross-validation
% cfg.design = make_design_similarity_cv(cfg);
cfg.results.overwrite = 1; %overwrite results each time to save space
% Run decoding
results = decoding(cfg);