⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rri_boot_check.m

📁 matlab里的PLS回归分析,含英文说明,比较复杂
💻 M
字号:
function [min_subj_per_group, is_boot_samples, boot_samples, new_num_boot] ...
	= rri_boot_check(num_subj_lst, num_cond, num_boot, incl_seq, ...
		for_batch)

   if ~exist('for_batch', 'var')
      for_batch = 0;
   end

   if ~exist('incl_seq','var')
      incl_seq = 0;
   end

   total_subj = sum(num_subj_lst);
   num_group = length(num_subj_lst);
   total_rows = num_cond * total_subj;

   min_subj_per_group = [];
   is_boot_samples = [];
   boot_samples = [];

   new_num_boot = num_boot;
   percentage = [];
   done = 0;

   %  num_subj in one of group is less than 3
   %
   if (min(num_subj_lst) < 3)

%      if exist('progress_hdl','var')
%         close(progress_hdl);
%      end

      msg = 'Bootstrap analysis requires that each group must have at least 3 subjects';
      uiwait(msgbox(msg,'ERROR','modal'));
%      disp('At least 3 subjects must be chosen for bootstrap analysis.');

%      boot_order = [];
      new_num_boot = 0;
      return;
   end;

   if for_batch
      percentage = 50;
   else
      while ~done
         msg = 'Please input a percentage number (between 30 and 70) that will represent a minimum number of different subjects in bootstrap versus total number of subjects you have. If you are not sure, please accept the default value which is equal to 50 percent:';
         tmp = inputdlg({msg}, 'Percentage of minimum different subject number', 1, {'50'});

         if isempty(tmp)
%            if exist('progress_hdl','var')
%               close(progress_hdl);
%            end

%            boot_order = [];
            new_num_boot = 0;
            return;
         end

         percentage = str2num(tmp{1});

         if isempty(percentage) | percentage < 30 | percentage > 70
            done = 0;
         else
            done = 1;
         end
      end
   end

   min_subj_per_group = ceil(min(num_subj_lst)*percentage/100);
   max_subj_per_group = 8;
%   tmp_boot_order = [];
%   progress_hdl = rri_progress_ui('initialize');

   %  if num of subj is 8 or less, we can get from boot matrix
   %
   is_boot_samples = zeros(1,num_group);
   boot_samples = cell(1,num_group);
   rand('state',sum(100*clock));

   if (sum(num_subj_lst <= max_subj_per_group) == num_group)

      for g = 1:num_group

         num_subj = num_subj_lst(g);
%         diff_subj = min_subj_per_group;

         boot_sample2 = [];

         %  remove sequential order
         %
         if incl_seq
            max_diff_subj = num_subj;
         else
            max_diff_subj = num_subj - 1;
         end

         for diff_subj = min_subj_per_group:max_diff_subj
            boot_sample1 = rri_boot_samples(num_subj, diff_subj);
            boot_sample2 = [boot_sample2; boot_sample1];
         end

         num_boot_samples = size(boot_sample2, 1);

         while num_boot_samples < new_num_boot

            done = 0;
            while ~done
               msg1 = [num2str(num_subj), ' subjects can only have ',num2str(num_boot_samples), ...
			' different bootstrap samples. Please reduce the number of bootstrap:'];
               msg2 = 'Or, please choose another percentage number (between 30 and 70) that will represent a minimum number of different subjects in bootstrap versus total number of subjects you have. If you are not sure, please accept the default value which is equal to 50 percent:';
               tmp = inputdlg({msg1, msg2}, 'Edit', 1, {num2str(new_num_boot), num2str(percentage)});

               if isempty(tmp)
%                  if exist('progress_hdl','var')
%                     close(progress_hdl);
%                  end

%                  boot_order = [];
                  new_num_boot = 0;
                  return;
               end

               new_num_boot = str2num(tmp{1});
               percentage = str2num(tmp{2});
               min_subj_per_group = ceil(min(num_subj_lst)*percentage/100);

               if isempty(percentage) | percentage < 30 | percentage > 70 | new_num_boot < 1
                  done = 0;
               else
                  done = 1;
               end
            end

            if isempty(tmp)
%               if exist('progress_hdl','var')
%                  close(progress_hdl);
%               end

               msg = 'You need more subjects in order to run bootstrap again.';
               uiwait(msgbox(msg,'ERROR','modal'));

%               boot_order = [];
               new_num_boot = 0;
               return;
            end

            boot_sample2 = [];

            %  remove sequential order
            %
            if incl_seq
               max_diff_subj = num_subj;
            else
               max_diff_subj = num_subj - 1;
            end

            for diff_subj = min_subj_per_group:max_diff_subj
               boot_sample1 = rri_boot_samples(num_subj, diff_subj);
               boot_sample2 = [boot_sample2; boot_sample1];
            end

            num_boot_samples = size(boot_sample2, 1);

         end	% while

         if ~isempty(boot_sample2)
            boot_sample2 = boot_sample2(randperm(num_boot_samples),:);
            boot_samples{g} = boot_sample2;
            is_boot_samples(g) = 1;
         end

      end	% for
   end		% if

   return;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -