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

📄 rri_boot_check.m

📁 国外的一个PLStoolbox,主要用于处理图象,也可以用来回归,欢迎使用
💻 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, nopopup)

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

   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

      if nopopup
         disp('Bootstrap analysis requires that each group must have at least 3 subjects');
      else
         msg = 'Bootstrap analysis requires that each group must have at least 3 subjects';
         uiwait(msgbox(msg,'ERROR','modal'));
      end
%      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
         if nopopup
            disp(' ');disp('Please input a percentage number (between 30 and 70) that will represent a');
            disp('minimum number of different subjects in bootstrap versus total number of');
            msg = 'subjects you have. If you are not sure, please use 50 percent: ';
            tmp=input(msg, 's');disp(' ');

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

%               boot_order = [];
               new_num_boot = 0;
               return;
            else
               tmp = {tmp};
            end
         else
            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{1})
%               if exist('progress_hdl','var')
%                  close(progress_hdl);
%               end

%               boot_order = [];
               new_num_boot = 0;
               return;
            end
         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
               if nopopup
                  disp(' ');disp([num2str(num_subj), ' subjects can only have ',num2str(num_boot_samples), ...
			' different bootstrap samples. Please reduce the']);
                  disp('number of bootstrap (you also have option to choose another percentage');
                  msg1 = 'number later): ';
                  tmp1=input(msg1, 's');disp(' ');

                  disp(' ');disp('If you fail to reduce the number of bootstrap, please reduce percentage');
                  disp('number now (between 30 and 70) that will represent a minimum number of');
                  disp('different subjects in bootstrap versus total number of subjects you have.');
                  msg2 = 'If you are not sure, please use 50 percent: ';
                  tmp2=input(msg2, 's');disp(' ');

                  if isempty(tmp1) | isempty(tmp2)
%                     if exist('progress_hdl','var')
%                        close(progress_hdl);
%                     end

%                     boot_order = [];
                     new_num_boot = 0;
                     return;
                  else
                     tmp = {tmp1, tmp2};
                  end
               else
                  msg1 = [num2str(num_subj), ' subjects can only have ',num2str(num_boot_samples), ...
			' different bootstrap samples. Please reduce the number of bootstrap:'];
                  msg2 = 'Or, please reduce 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{1}) | isempty(tmp{2})
%                     if exist('progress_hdl','var')
%                        close(progress_hdl);
%                     end

%                     boot_order = [];
                     new_num_boot = 0;
                     return;
                  end
               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

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

%               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 + -