当前位置:   article > 正文

MRI学习笔记-spm独立样本t检验

MRI学习笔记-spm独立样本t检验

SPM操作:

9-SPM-fmri任务态 二阶分析: 双样本t检验 - 知乎 (zhihu.com)

批处理脚本:

  1. clc;
  2. clear;
  3. nmodel = '3';
  4. numsub = 27;
  5. rootdir = 'D:\LLYdata\motor_inhibition_data2\motor_inhibition_fmri';%数据最上层路径
  6. ffxname = 'data_05_1st_level2';%1st分析文件名
  7. rfxname = 'data_09_independentTtest';%2st分析文件名
  8. batchfilename = 'batchfiles';%batchfiles文件名
  9. ffxdir = fullfile(rootdir,ffxname,strcat('M',nmodel));%1st分析完整路径
  10. rfxdir = fullfile(rootdir,rfxname,strcat('M',nmodel));%2st分析完整路径
  11. load(fullfile(rfxdir,'conpos.mat'));
  12. load(fullfile(rfxdir,'conneg.mat'));
  13. %%
  14. group1 = {'02';'04';'05';'10';'12';'13';'14';'15';'18';'24';'25';'26';'27'};%低成本
  15. group2 = {'01';'03';'06';'07';'08';'09';'11';'16';'17';'19';'20';'21';'22';'23'};%高成本
  16. %% 生成conname
  17. %%%删除其中的*
  18. for i = 1:size(conpos,2)
  19. if contains(conpos(1,i), '*')
  20. conpos(1,i) = strrep(conpos(1,i), '*', '');
  21. end
  22. if contains(conneg(1,i), '*')
  23. conneg(1,i) = strrep(conneg(1,i), '*', '');
  24. end
  25. end
  26. conname = cell(1,1);
  27. for ncon = 1:size(conpos,2)
  28. if ncon == 1
  29. conname{end} = strcat(conpos{ncon},'-',conneg{ncon});
  30. else
  31. conname{end+1} = strcat(conpos{ncon},'-',conneg{ncon});
  32. end
  33. conname{end+1} = strcat(conneg{ncon},'-',conpos{ncon});
  34. end
  35. %%
  36. jobfile = [];
  37. spm('defaults','fmri')
  38. for ncon = 1:2*size(conpos,2)
  39. clear matlabbatch
  40. %%%生成保存结果的路径
  41. if ~exist(fullfile(rfxdir,conname{ncon}),'dir')
  42. mkdir(fullfile(rfxdir,conname{ncon}));
  43. end
  44. %%%group data path
  45. for nsub = 1:size(group1,1)
  46. group1_path{nsub,1} = fullfile(ffxdir,group1{nsub},strcat(sprintf('con_%04d',ncon),'.nii,1'));
  47. end
  48. for nsub = 1:size(group2,1)
  49. group2_path{nsub,1} = fullfile(ffxdir,group2{nsub},strcat(sprintf('con_%04d',ncon),'.nii,1'));
  50. end
  51. %%
  52. matlabbatch{1}.spm.stats.factorial_design.dir = {fullfile(rfxdir,conname{ncon})};
  53. matlabbatch{1}.spm.stats.factorial_design.des.t2.scans1 = group1_path;
  54. %%
  55. %%
  56. matlabbatch{1}.spm.stats.factorial_design.des.t2.scans2 = group2_path;
  57. %%
  58. matlabbatch{1}.spm.stats.factorial_design.des.t2.dept = 0;
  59. matlabbatch{1}.spm.stats.factorial_design.des.t2.variance = 1;
  60. matlabbatch{1}.spm.stats.factorial_design.des.t2.gmsca = 0;
  61. matlabbatch{1}.spm.stats.factorial_design.des.t2.ancova = 0;
  62. %%
  63. matlabbatch{1}.spm.stats.factorial_design.cov(1).c = [22
  64. 20
  65. 20
  66. 20
  67. 18
  68. 25
  69. 25
  70. 25
  71. 25
  72. 21
  73. 19
  74. 26
  75. 20
  76. 28
  77. 21
  78. 25
  79. 20
  80. 26
  81. 21
  82. 25
  83. 19
  84. 19
  85. 27
  86. 23
  87. 19
  88. 19
  89. 23
  90. ];
  91. %%
  92. matlabbatch{1}.spm.stats.factorial_design.cov(1).cname = 'age';
  93. matlabbatch{1}.spm.stats.factorial_design.cov(1).iCFI = 1;
  94. matlabbatch{1}.spm.stats.factorial_design.cov(1).iCC = 1;
  95. %%
  96. matlabbatch{1}.spm.stats.factorial_design.cov(2).c = [2
  97. 2
  98. 1
  99. 1
  100. 1
  101. 1
  102. 2
  103. 2
  104. 1
  105. 2
  106. 1
  107. 1
  108. 2
  109. 1
  110. 2
  111. 2
  112. 1
  113. 1
  114. 1
  115. 2
  116. 1
  117. 1
  118. 2
  119. 1
  120. 1
  121. 2
  122. 2
  123. ];
  124. %%
  125. matlabbatch{1}.spm.stats.factorial_design.cov(2).cname = 'sex';
  126. matlabbatch{1}.spm.stats.factorial_design.cov(2).iCFI = 1;
  127. matlabbatch{1}.spm.stats.factorial_design.cov(2).iCC = 1;
  128. matlabbatch{1}.spm.stats.factorial_design.multi_cov = struct('files', {}, 'iCFI', {}, 'iCC', {});
  129. matlabbatch{1}.spm.stats.factorial_design.masking.tm.tm_none = 1;
  130. matlabbatch{1}.spm.stats.factorial_design.masking.im = 1;
  131. matlabbatch{1}.spm.stats.factorial_design.masking.em = {'E:\MATLAB\toolbox\spm12\tpm\mask_ICV.nii,1'};
  132. matlabbatch{1}.spm.stats.factorial_design.globalc.g_omit = 1;
  133. matlabbatch{1}.spm.stats.factorial_design.globalm.gmsca.gmsca_no = 1;
  134. matlabbatch{1}.spm.stats.factorial_design.globalm.glonorm = 1;
  135. matlabbatch{2}.spm.stats.fmri_est.spmmat(1) = cfg_dep('Factorial design specification: SPM.mat File', substruct('.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','spmmat'));
  136. matlabbatch{2}.spm.stats.fmri_est.write_residuals = 0;
  137. matlabbatch{2}.spm.stats.fmri_est.method.Classical = 1;
  138. matlabbatch{3}.spm.stats.con.spmmat(1) = cfg_dep('Model estimation: SPM.mat File', substruct('.','val', '{}',{2}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','spmmat'));
  139. matlabbatch{3}.spm.stats.con.consess{1}.tcon.name = 'g1>g2';
  140. matlabbatch{3}.spm.stats.con.consess{1}.tcon.weights = [1 -1];
  141. matlabbatch{3}.spm.stats.con.consess{1}.tcon.sessrep = 'none';
  142. matlabbatch{3}.spm.stats.con.consess{2}.tcon.name = 'g1<g2';
  143. matlabbatch{3}.spm.stats.con.consess{2}.tcon.weights = [-1 1];
  144. matlabbatch{3}.spm.stats.con.consess{2}.tcon.sessrep = 'none';
  145. matlabbatch{3}.spm.stats.con.delete = 0;
  146. %% Save new job file
  147. %%%生成保存batch的路径
  148. batchfilesdir = fullfile(rfxdir,batchfilename);
  149. if ~exist(batchfilesdir,'dir')
  150. mkdir(batchfilesdir);
  151. end
  152. batchfile = conname{ncon};
  153. save(fullfile(batchfilesdir,batchfile),'matlabbatch');
  154. jobfile{end+1,1} = fullfile(batchfilesdir,batchfile);
  155. fprintf('Saved batch file %s\n',batchfile)%命令行输出文字反馈
  156. end
  157. spm('chmod','fmri');
  158. spm('defaults','fmri');

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/537784
推荐阅读
相关标签
  

闽ICP备14008679号