|
| 1 | +%% Multi-level kernel density (MKDA) meta-analysis example: Agency database |
| 2 | +% The starting point for coordinate-based meta-analysis (CBMA) is a text file |
| 3 | +% with the information entered from published studies. In this example, the |
| 4 | +% information is contained in the file "Agency_meta_analysis_database.txt" |
| 5 | +% It is in the Neuroimaging_Pattern_Masks repository on Github. |
| 6 | +% |
| 7 | +% This file should be on your Matlab path: |
| 8 | +% Neuroimaging_Pattern_Masks/CANlab_Meta_analysis_maps/2011_Agency_Meta_analysis/Agency_meta_analysis_database.txt |
| 9 | + |
| 10 | +%% Section 1: Locate the coordinate database file |
| 11 | +% When you set up your own database, several rules apply. Formatting the spreadsheet |
| 12 | +% so it loads correctly can sometimes be the hardest part of running a |
| 13 | +% meta-analysis. |
| 14 | +% |
| 15 | +% See https://canlabweb.colorado.edu/wiki/doku.php/help/meta/meta_analysis_mkda |
| 16 | +% |
| 17 | +% And https://canlabweb.colorado.edu/wiki/doku.php/help/meta/database |
| 18 | +% |
| 19 | +% Here are some rules for setting up the file: |
| 20 | +% 1 The variable "dbname" in the workspace should specify the name of your coordinate database file |
| 21 | +% 2 The database must be a text file, tab delimited |
| 22 | +% 3 The 1st row of the database must contain the number of columns as its 1st and only entry |
| 23 | +% 4 The 2nd row of database must contain variable names (text, no spaces or special characters) |
| 24 | +% 5 The 3rd - nth rows of the database contains data |
| 25 | +% 6 Talairach coordinates are indicated by T88 in CoordSys variable |
| 26 | +% 7 coordinate fields should be called x, y, and z |
| 27 | +% 8 Do NOT use Z, or any other field name in clusters structure |
| 28 | +% |
| 29 | +% The second row of your database should contain names for each variable |
| 30 | +% you have coded. Some variables should be named with special keywords, |
| 31 | +% because they are used in the meta-analysis code. Other variables can be named |
| 32 | +% anything, as long as there are *no spaces or special characters* in the |
| 33 | +% name (e.g., !@#$%^&*(){}[] ~`\/|<>,.?/;:"''+=). |
| 34 | +% Anything that you could not name a variable in Matlab will also not work |
| 35 | +% here. |
| 36 | +% Here are the variable names with special meaning. They are case-sensitive: |
| 37 | +% |
| 38 | +% Subjects : Sample size of the study to which the coordinate belongs |
| 39 | +% FixedRandom : Study used fixed or random effects. |
| 40 | +% Values should be Fixed or Random. |
| 41 | +% Fixed effects coordinates will be automatically |
| 42 | +% downweighted |
| 43 | +% SubjectiveWeights : A coordinate or contrast weighting vector based on FixedRandom |
| 44 | +% and whatever else you want to weight by; e.g., study reporting threshold |
| 45 | +% The default is to use FixedRandom only if available |
| 46 | +% x, y, z : X, Y, and Z coordinates |
| 47 | +% study : name of study |
| 48 | +% Contrast : unique indices (e.g., 1:k) for each independent |
| 49 | +% contrast. This is a required variable! |
| 50 | +% All rows belonging to the same contrast should |
| 51 | +% (almost) always have the same values for every |
| 52 | +% variable other than x, y, and z. |
| 53 | +% CoordSys : Values should be MNI or T88, for MNI space or Talairach space |
| 54 | +% Talairach coordinates will be converted to MNI using |
| 55 | +% Matthew Brett's transform |
| 56 | + |
| 57 | +dbfilename = 'Agency_meta_analysis_database.txt'; |
| 58 | +dbname = which(dbfilename); |
| 59 | + |
| 60 | +if isempty(dbname), error('Cannot locate the file %s\nMake sure it is on your Matlab path.', dbfilename); end |
| 61 | + |
| 62 | +%% Section 2: Read in and set up the coordinate database |
| 63 | +% ------------------------------------------------------------------------- |
| 64 | + |
| 65 | +% First, create a new directory for the analysis and go there: |
| 66 | +analysisdir = fullfile(pwd, 'Agency_meta_analysis_example'); |
| 67 | +mkdir(analysisdir) |
| 68 | +cd(analysisdir) |
| 69 | + |
| 70 | +% Read in the database and save it in a structure variable called "DB" |
| 71 | +clear DB |
| 72 | +read_database; |
| 73 | + |
| 74 | +% Create SubjectiveWeights |
| 75 | +% DB.SubjectiveWeights = zeros(size(DB.x)); |
| 76 | +% DB.SubjectiveWeights(strcmp(DB.FixedRandom, 'Random')) = 1; |
| 77 | +% DB.SubjectiveWeights(strcmp(DB.FixedRandom, 'Fixed')) = 0.75; |
| 78 | + |
| 79 | +% Prepare the database by checking fields and separating contrasts, |
| 80 | +% specifying a 10 mm radius for integrating coordinates: |
| 81 | +DB = Meta_Setup(DB, 10); |
| 82 | + |
| 83 | +% Meta_Setup automatically saves a file called SETUP.mat in your folder as well. |
| 84 | +drawnow, snapnow |
| 85 | +close |
| 86 | + |
| 87 | +%% Check and clean up any variables that need recoding |
| 88 | +% This is a good time to examine the DB structure to check whether the variables |
| 89 | +% you entered look as intended (numeric or text), and clean up any |
| 90 | +% variables that need recoding. |
| 91 | +% Sometimes, if text characters are entered |
| 92 | +% in the spreadsheet in a column of numbers, the entire column will be read |
| 93 | +% in as text. |
| 94 | +% Other times, variable entries with the same intended category/level will |
| 95 | +% have different names, e.g., yes vs. Yes (all entries are |
| 96 | +% case-sensitive). You can either fix these in the spreadsheet (best) or |
| 97 | +% re-code them here. |
| 98 | +% |
| 99 | +% There is no re-coding needed for this dataset, but here is an example: |
| 100 | +% e.g., |
| 101 | +% wh = strcmp(DB.Increased_craving, 'yes'); DB.Increased_craving(wh) = {'Yes'}; |
| 102 | + |
| 103 | +% If you do re-code, do this afterwards: |
| 104 | +% save SETUP -append DB |
| 105 | + |
| 106 | +%% Select a subset of contrasts |
| 107 | +% The function Meta_Select_Contrasts allows you to select a subset of the |
| 108 | +% database (DB variable) based on a combination of selected levels on |
| 109 | +% multiple variables. We will skip that for this example, but if you do |
| 110 | +% select variables, it is a good idea to create a subfolder for the |
| 111 | +% analysis with selected coordinates, and save the DB variable in SETUP.mat |
| 112 | +% in that folder, along with other results you may generate. |
| 113 | + |
| 114 | +%% Convolve with spheres and set up the study indicator dataset |
| 115 | +% ------------------------------------------------------------------------- |
| 116 | +% This step prepares the dataset for meta-analysis and runs the entire |
| 117 | +% analysis. It then generates results maps. |
| 118 | +% |
| 119 | +% It will generate new files for the analysis, so it is a good idea to |
| 120 | +% create and go to a subfolder that will contain files for this analysis. |
| 121 | +% Many meta-analysis projects involve several analyses, in several |
| 122 | +% sub-folders. |
| 123 | + |
| 124 | +modeldir = fullfile(analysisdir, 'MKDA_all_contrasts'); |
| 125 | +mkdir(modeldir) |
| 126 | +cd(modeldir) |
| 127 | + |
| 128 | +Meta_Activation_FWE('all', DB, 100, 'nocontrasts', 'noverbose'); |
| 129 | + |
| 130 | +% Note: For a "final" analysis, 10,000 iterations are recommended |
| 131 | +% Because we typically care about inferences at the "tails" of the |
| 132 | +% sampling distribution (i.e., voxels with low P-values) |
| 133 | +% |
| 134 | +% Note: You can also use Meta_Activation_FWE to do each piece separately: |
| 135 | +% |
| 136 | +% Meta_Activation_FWE('setup') % sets up the analysis |
| 137 | +% Meta_Activation_FWE('mc', 10000) % Adds 10,000 Monte Carlo iterations |
| 138 | +% |
| 139 | +% A file is saved every 10 iterations, so if there are existing saved iterations |
| 140 | +% this will find them and add more. |
| 141 | +% |
| 142 | +% Meta_Activation_FWE('results') % generates results maps |
| 143 | + |
| 144 | +drawnow |
| 145 | +snapnow |
| 146 | + |
0 commit comments