Home > data-analysis > stats > cevent > cevent_cal_stats.m

cevent_cal_stats

PURPOSE ^

CEVENT_CAL_STATS Report various stypes of statistics of cevent data

SYNOPSIS ^

function results = cevent_cal_stats(chunks, input)

DESCRIPTION ^

CEVENT_CAL_STATS Report various stypes of statistics of cevent data
chunks according to user input.
 
 INPUT: 
   CHUNKS: a cell of data. See also GET_VARIABLE,
   GET_VARIABLE_BY_GROUPING, GET_VARIABLE_BY_SUBJECT,
   GET_VARIABLE_BY_TRIAL, GET_VARIABLE_BY_EVENT, GET_VARIABLE_BY_CEVENT.
   INPUT: (optional parameter) a struct that specifies the types of
   statistics user wants to calculate. Optional fields are:
       grouping: the grouping method of data chunks, see
       GET_VARIABLE_BY_GROUPING;
       categories: categories existing in the data chunks;
       nodata_marker: which category value will be considered as non-data
       in generating transition matrix;
       trans_max_gap: the maximum timing gap that is allowed for two
       cevents to be considered as consecutive events in generating
       transition matrix;
       individual_range_dur: only when data chunks are extracted in
       grouping method 'trial' or 'subject', this field is allowed. And,
       the existence of this field will lead to calculation of proportion
       and frequency in results.
       hist_bins: bins for generating histogram according to categories.
       high_threshold: for calculating the proportion of time that data
       has a category value larger than this category value**;
       low_threshold:
       whence: value 'start' or 'end', indicating whether the chunks of
       data were extracted based on onset/offser of a certain types of
       events/cevents.
       interval: used with the parameter WHENCE, indicating the starting
       time and ending time when chunks were extracted based on
       events/cevents.

 OUTPUT:
   RESULTS: a struct containing all the statistics. Also, individual
   statistic within one chunk of data will be reported.

 EXAMPLE:
     exp_id = 53;
     sub_list = list_subjects(exp_id);

     input.sub_list = sub_list;
     input.var_name = 'cevent_human_eye_roi';
     input.grouping = 'trial';

     chunks = get_variable_by_grouping('sub', input.sub_list, input.var_name, ...
         input.grouping, input);

     chunks_trial_time = arrayfun(@(sub_id) ...
         get_trial_times(sub_id), ...
         input.sub_list, ...
         'UniformOutput', false);
     individual_range_dur = vertcat(chunks_trial_time{:});
     individual_range_dur = individual_range_dur(:,2) - individual_range_dur(:,1);
     input.individual_range_dur = individual_range_dur;

     results = cevent_cal_stats(chunks, input);
 Example results:
     results =
                       categories: [1 2 3 4]
                     total_number: 6459
                individual_number: [59x1 double]
              total_number_by_cat: [1286 1902 1279 1992]
         individual_number_by_cat: [59x4 double]
                         mean_dur: 0.9074
              individual_mean_dur: [59x1 double]
                  mean_dur_by_cat: [1.2025 0.8770 1.1315 0.6020]
       individual_mean_dur_by_cat: [59x4 double]
                       median_dur: 0.4220
                median_dur_by_cat: [0.5160 0.3600 0.4690 0.4210]
                             prop: 0.8279
                      prop_by_cat: [0.2639 0.2846 0.2469 0.2046]
                  individual_prop: [59x1 double]
           individual_prop_by_cat: [59x4 double]
                             freq: 54.7462
                      freq_by_cat: [10.9001 16.1213 10.8408 16.8841]
                  individual_freq: [59x1 double]
           individual_freq_by_cat: [59x4 double]
                 range_time_total: 7.0788e+003
            individual_range_dur: [59x1 double]
                         switches: 43.6512
              individual_switches: [59x1 double]
                     trans_matrix: [4x4 double]
          individual_trans_matrix: {59x1 cell}
                trans_freq_matrix: [4x4 double]
     individual_trans_freq_matrix: {59x1 cell}

   See also: EVENT_SINGLE_STATS, GET_VARIABLE_BY_GROUPING

 For more example, go to:
 https://einstein.psych.indiana.edu/trac/browser/projects/txu_remodule/txu_test_stats_cevent.m

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function results = cevent_cal_stats(chunks, input)
0002 
0003 %CEVENT_CAL_STATS Report various stypes of statistics of cevent data
0004 %chunks according to user input.
0005 %
0006 % INPUT:
0007 %   CHUNKS: a cell of data. See also GET_VARIABLE,
0008 %   GET_VARIABLE_BY_GROUPING, GET_VARIABLE_BY_SUBJECT,
0009 %   GET_VARIABLE_BY_TRIAL, GET_VARIABLE_BY_EVENT, GET_VARIABLE_BY_CEVENT.
0010 %   INPUT: (optional parameter) a struct that specifies the types of
0011 %   statistics user wants to calculate. Optional fields are:
0012 %       grouping: the grouping method of data chunks, see
0013 %       GET_VARIABLE_BY_GROUPING;
0014 %       categories: categories existing in the data chunks;
0015 %       nodata_marker: which category value will be considered as non-data
0016 %       in generating transition matrix;
0017 %       trans_max_gap: the maximum timing gap that is allowed for two
0018 %       cevents to be considered as consecutive events in generating
0019 %       transition matrix;
0020 %       individual_range_dur: only when data chunks are extracted in
0021 %       grouping method 'trial' or 'subject', this field is allowed. And,
0022 %       the existence of this field will lead to calculation of proportion
0023 %       and frequency in results.
0024 %       hist_bins: bins for generating histogram according to categories.
0025 %       high_threshold: for calculating the proportion of time that data
0026 %       has a category value larger than this category value**;
0027 %       low_threshold:
0028 %       whence: value 'start' or 'end', indicating whether the chunks of
0029 %       data were extracted based on onset/offser of a certain types of
0030 %       events/cevents.
0031 %       interval: used with the parameter WHENCE, indicating the starting
0032 %       time and ending time when chunks were extracted based on
0033 %       events/cevents.
0034 %
0035 % OUTPUT:
0036 %   RESULTS: a struct containing all the statistics. Also, individual
0037 %   statistic within one chunk of data will be reported.
0038 %
0039 % EXAMPLE:
0040 %     exp_id = 53;
0041 %     sub_list = list_subjects(exp_id);
0042 %
0043 %     input.sub_list = sub_list;
0044 %     input.var_name = 'cevent_human_eye_roi';
0045 %     input.grouping = 'trial';
0046 %
0047 %     chunks = get_variable_by_grouping('sub', input.sub_list, input.var_name, ...
0048 %         input.grouping, input);
0049 %
0050 %     chunks_trial_time = arrayfun(@(sub_id) ...
0051 %         get_trial_times(sub_id), ...
0052 %         input.sub_list, ...
0053 %         'UniformOutput', false);
0054 %     individual_range_dur = vertcat(chunks_trial_time{:});
0055 %     individual_range_dur = individual_range_dur(:,2) - individual_range_dur(:,1);
0056 %     input.individual_range_dur = individual_range_dur;
0057 %
0058 %     results = cevent_cal_stats(chunks, input);
0059 % Example results:
0060 %     results =
0061 %                       categories: [1 2 3 4]
0062 %                     total_number: 6459
0063 %                individual_number: [59x1 double]
0064 %              total_number_by_cat: [1286 1902 1279 1992]
0065 %         individual_number_by_cat: [59x4 double]
0066 %                         mean_dur: 0.9074
0067 %              individual_mean_dur: [59x1 double]
0068 %                  mean_dur_by_cat: [1.2025 0.8770 1.1315 0.6020]
0069 %       individual_mean_dur_by_cat: [59x4 double]
0070 %                       median_dur: 0.4220
0071 %                median_dur_by_cat: [0.5160 0.3600 0.4690 0.4210]
0072 %                             prop: 0.8279
0073 %                      prop_by_cat: [0.2639 0.2846 0.2469 0.2046]
0074 %                  individual_prop: [59x1 double]
0075 %           individual_prop_by_cat: [59x4 double]
0076 %                             freq: 54.7462
0077 %                      freq_by_cat: [10.9001 16.1213 10.8408 16.8841]
0078 %                  individual_freq: [59x1 double]
0079 %           individual_freq_by_cat: [59x4 double]
0080 %                 range_time_total: 7.0788e+003
0081 %            individual_range_dur: [59x1 double]
0082 %                         switches: 43.6512
0083 %              individual_switches: [59x1 double]
0084 %                     trans_matrix: [4x4 double]
0085 %          individual_trans_matrix: {59x1 cell}
0086 %                trans_freq_matrix: [4x4 double]
0087 %     individual_trans_freq_matrix: {59x1 cell}
0088 %
0089 %   See also: EVENT_SINGLE_STATS, GET_VARIABLE_BY_GROUPING
0090 %
0091 % For more example, go to:
0092 % https://einstein.psych.indiana.edu/trac/browser/projects/txu_remodule/txu_test_stats_cevent.m
0093 
0094 if isempty(chunks)
0095     warning('The input CHUNKS is empty, there is no data inside, the function will return now');
0096     results = [];
0097     return
0098 end
0099 
0100 % check fileds in 'input'
0101 if ~exist('input', 'var')
0102     % this line of code is just to prevent from generating errors when
0103     % script checks whether a certain field exists.
0104     input.none_filed = 'No information here';
0105 end
0106 
0107 % if isfield(input, 'var_name')
0108 %     if ~strcmp(get_data_type(input.var_name), 'cevent')
0109 %         error('Error! This function can only accept CEVENT data type');
0110 %     end
0111 % end
0112 
0113 if isfield(input, 'sub_list')
0114     results.sub_list = input.sub_list;
0115 end
0116 
0117 if isfield(input, 'grouping')
0118     grouping = input.grouping;
0119 else
0120     grouping = '';
0121 end
0122 
0123 % If user only wants to calculate stats for cevents that fall within a
0124 % specified duration range
0125 if isfield(input, 'min_dur_thresh')
0126     for cidx = 1:length(chunks)
0127         chunk_one = chunks{cidx};
0128         if size(chunk_one, 1) > 0
0129             chunk_one = cevent_remove_small_segments(...
0130                 chunk_one, input.min_dur_thresh);
0131         end
0132         chunks{cidx} = chunk_one;
0133     end
0134 end
0135 
0136 if isfield(input, 'max_dur_thresh') 
0137     for cidx = 1:length(chunks)
0138         chunk_one = chunks{cidx};
0139         if size(chunk_one, 1) > 0
0140             chunk_one = cevent_remove_long_segments(...
0141                 chunk_one, input.max_dur_thresh);
0142         end
0143         chunks{cidx} = chunk_one;
0144     end
0145 end
0146 
0147 cat_chunks = cat(1,chunks{:});
0148 
0149 if isfield(input, 'categories')
0150     categories = input.categories;
0151     results.categories = categories;
0152 else
0153     categories = unique(cat_chunks(:,3))';
0154     if isfield(input, 'nodata_marker')
0155         categories = categories(~ismember(categories, input.nodata_marker));
0156     end
0157     results.categories = categories;
0158 end
0159 if all(cellfun(@isempty, chunks))
0160     max_category = 1;
0161 else
0162     max_category = nanmax(nanmax(cat_chunks(:,3)), max(categories));
0163 end
0164 
0165 % the calculation of individual_range_dur should be done
0166 % in the step of extracting data
0167 if isfield(input, 'individual_range_dur')
0168     individual_range_dur = input.individual_range_dur;
0169     
0170     if size(individual_range_dur, 1) == 1
0171         individual_range_dur = repmat(individual_range_dur, ...
0172             length(chunks), 1);
0173         input.individual_range_dur = individual_range_dur;
0174     elseif length(chunks) ~= length(individual_range_dur)
0175         warning(['Warning: the length of data chunks and the length ' ...
0176             'of individual_range_dur are not the same, therefore, ' ...
0177             'input.individual_range_dur will be discarded.']);
0178         input = rmfield(input, 'individual_range_dur');
0179     end
0180 elseif strcmp(grouping, 'subject') && isfield(input, 'sub_list') ...
0181         && length(chunks) == length(input.sub_list)
0182     chunks_trial_time = arrayfun(@(sub_id) ...
0183         event_total_length(get_trial_times(sub_id)), ...
0184         input.sub_list, ...
0185         'UniformOutput', false);
0186     individual_range_dur = vertcat(chunks_trial_time{:});
0187     input.individual_range_dur = individual_range_dur;
0188 elseif strcmp(grouping, 'trial_cat') && isfield(input, 'sub_list') ...
0189         && length(chunks) == length(input.sub_list)
0190     chunks_trial_time = arrayfun(@(sub_id) ...
0191         event_total_length(get_trial_times(sub_id)), ...
0192         input.sub_list, ...
0193         'UniformOutput', false);
0194     individual_range_dur = vertcat(chunks_trial_time{:});
0195     input.individual_range_dur = individual_range_dur;
0196 elseif strcmp(grouping, 'trial') && isfield(input, 'sub_list') ...
0197         && (~isfield(input, 'trial_indices') && ~isfield(input, 'trial_var_name'))
0198     chunks_trial_time = arrayfun(@(sub_id) ...
0199         get_trial_times(sub_id), ...
0200         input.sub_list, ...
0201         'UniformOutput', false);
0202     individual_range_dur = vertcat(chunks_trial_time{:});
0203     individual_range_dur = individual_range_dur(:,2)-individual_range_dur(:,1);
0204     if length(individual_range_dur) == length(chunks)
0205         input.individual_range_dur = individual_range_dur;
0206     else
0207         disp(['If chunks are extracted based on selective trials, ' ...
0208             'either the field trial_indices or trial_var_name has to be set']);
0209     end
0210 elseif strcmp(grouping, 'trial') && isfield(input, 'sub_list') ...
0211         && isfield(input, 'trial_indices') && ~isfield(input, 'trial_var_name')
0212     sub_list = input.sub_list;
0213     individual_range_dur = [];
0214     
0215     for sidx = 1:length(sub_list)
0216         sub_id = sub_list(sidx);
0217         if iscell(input.trial_indices)
0218             trial_indices_one = input.trial_indices{sidx};
0219         else
0220             trial_indices_one = input.trial_indices;
0221         end
0222         trial_times_one = get_trial_times(sub_id, trial_indices_one);
0223         trial_times_one = trial_times_one(:,2)-trial_times_one(:,1);
0224         individual_range_dur = [individual_range_dur; trial_times_one];
0225     end
0226     input.individual_range_dur = individual_range_dur;
0227 elseif strcmp(grouping, 'trial') && isfield(input, 'sub_list') ...
0228         && ~isfield(input, 'trial_indices') && isfield(input, 'trial_var_name')
0229     sub_list = input.sub_list;
0230     individual_range_dur = [];
0231     
0232     for sidx = 1:length(sub_list)
0233         sub_id = sub_list(sidx);
0234         if iscell(input.trial_indices)
0235             trial_indices_one = input.trial_indices{sidx};
0236         else
0237             trial_indices_one = input.trial_indices;
0238         end
0239         trial_times_one = get_trial_times(sub_id, trial_indices_one);
0240         trial_times_one = trial_times_one(:,2)-trial_times_one(:,1);
0241         individual_range_dur = [individual_range_dur; trial_times_one];
0242     end
0243     input.individual_range_dur = individual_range_dur;
0244 end
0245 
0246 %% calculate statistics
0247 cat_chunks_by_cat = arrayfun(@(category_one) ...
0248     cevent_category_equals(cat_chunks, category_one), ...
0249     categories, ...
0250     'UniformOutput', false);
0251 
0252 cat_chunks = cevent_category_equals(cat_chunks, categories);
0253 cat_durations = cat_chunks(:,2) - cat_chunks(:,1);
0254 
0255 if sum(ismember([0 NaN], unique(cat_chunks(:,3)))) > 0
0256     warning(['This cevent variable contains category value 0, ' ...
0257         'transition matrix cannot be calculated']);
0258     has_transition_matrix = false;
0259 else
0260     has_transition_matrix = true;
0261 end
0262 
0263 % loop through each chunk for calculating some statistics
0264 individual_number = zeros(length(chunks), 1);
0265 individual_number_by_cat = zeros(length(chunks), length(categories));
0266 individual_mean_dur = nan(length(chunks), 1);
0267 individual_std_dur = nan(length(chunks), 1);
0268 individual_median_dur = nan(length(chunks), 1);
0269 individual_mean_dur_by_cat = nan(length(chunks), length(categories));
0270 individual_median_dur_by_cat = nan(length(chunks), length(categories));
0271 % individual_stats = cell(length(chunks), 1);
0272 
0273 res_trans_matrix = zeros(length(categories), length(categories));
0274 res_individual_trans_matrix = cell(length(chunks), 1);
0275 res_individual_trans_freq_matrix = cell(length(chunks), 1);
0276 
0277 for chunkidx = 1:length(chunks)
0278     chunk_one = chunks{chunkidx};    
0279     
0280     if ~isempty(chunk_one)
0281         chunk_one = cevent_category_equals(chunk_one, categories);
0282     end
0283     
0284     if isempty(chunk_one)
0285         chunk_one = zeros(0, 3);
0286         chunk_one_by_cat = mat2cell(repmat(zeros(0, 3), 4, 1), ....
0287             zeros(1, 4), [3]);
0288         res_individual_trans_matrix{chunkidx} = [];
0289     end
0290     
0291     for catidx = 1:length(categories)
0292         category_one = cevent_category_equals( ...
0293             chunk_one, categories(catidx));
0294         
0295         individual_number_by_cat(chunkidx, catidx) = ...
0296             event_number(category_one);
0297         individual_mean_dur_by_cat(chunkidx, catidx) = ...
0298             event_average_dur(category_one);
0299         individual_median_dur_by_cat(chunkidx, catidx) = ...
0300             event_median_dur(category_one);
0301         
0302         chunk_one_by_cat = arrayfun(@(category_id) ...
0303             cevent_category_equals(chunk_one, category_id), ...
0304             categories, ...
0305             'UniformOutput', false);
0306     end
0307     
0308     individual_number(chunkidx) = event_number(chunk_one);
0309     individual_mean_dur(chunkidx) = event_average_dur(chunk_one);
0310     if isempty(chunk_one)
0311         individual_std_dur(chunkidx) = NaN;
0312     else
0313         individual_std_dur(chunkidx) = std(chunk_one(:,2) - chunk_one(:,1));
0314     end
0315     individual_median_dur(chunkidx) = event_median_dur(chunk_one);
0316     
0317     if has_transition_matrix
0318         if isempty(chunk_one)
0319             res_individual_trans_matrix{chunkidx} = ...
0320                 zeros(length(categories), length(categories));
0321             
0322             if isfield(input, 'individual_range_dur')
0323                 res_individual_trans_freq_matrix{chunkidx} = ...
0324                     zeros(length(categories), length(categories));
0325             end
0326 
0327         else
0328             % for calculating transition matrix for each chunk
0329             if isfield(input, 'trans_max_gap')        
0330                 trans_matrix_one = cevent_transition_matrix(chunk_one, ...
0331                     input.trans_max_gap, max_category);
0332             else
0333                 trans_matrix_one = cevent_transition_matrix(chunk_one, ...
0334                     Inf, max_category);
0335             end
0336             res_trans_matrix = res_trans_matrix + ...
0337                 trans_matrix_one(categories, categories);
0338 
0339             res_individual_trans_matrix{chunkidx} = ...
0340                 trans_matrix_one(categories, categories);
0341 
0342             if isfield(input, 'individual_range_dur')
0343                 res_individual_trans_freq_matrix{chunkidx} = ...
0344                     trans_matrix_one(categories, categories) / ...
0345                     individual_range_dur(chunkidx) * 60; % per minute
0346             end
0347         end
0348     end
0349     % temp_indiv_stats.trans_matrix = res_individual_trans_matrix{chunkidx};
0350     % individual_stats(chunkidx) = temp_indiv_stats;
0351 end
0352 
0353 % number of events
0354 % total number
0355 results.total_number = event_number(cat_chunks);
0356 % number by category
0357 res_total_number_by_cat = cellfun(@event_number,cat_chunks_by_cat, ...
0358     'UniformOutput', false);
0359 results.total_number_by_cat = horzcat(res_total_number_by_cat{:});
0360 results.individual_number = individual_number;
0361 results.individual_number_by_cat = individual_number_by_cat;
0362 results.mean_number = nanmean(individual_number);
0363 results.mean_number_by_cat = nanmean(individual_number_by_cat, 1);
0364 
0365 % mean duration
0366 % overal mean
0367 results.mean_dur = event_average_dur(cat_chunks);
0368 % mean by category
0369 res_mean_dur_by_cat = cellfun(@event_average_dur, cat_chunks_by_cat, ...
0370     'UniformOutput', false);
0371 results.mean_dur_by_cat = horzcat(res_mean_dur_by_cat{:});
0372 results.individual_mean_dur = individual_mean_dur;
0373 results.individual_mean_dur_by_cat = individual_mean_dur_by_cat;
0374 results.mean_mean_dur = nanmean(results.individual_mean_dur);
0375 results.mean_mean_dur_by_cat = nanmean(results.individual_mean_dur_by_cat, 1);
0376 results.individual_std_dur = individual_std_dur;
0377 % median durations
0378 results.median_dur = event_median_dur(cat_chunks);
0379 res_median_dur_by_cat = cellfun(@event_median_dur, cat_chunks_by_cat, ...
0380     'UniformOutput', false);
0381 results.median_dur_by_cat = horzcat(res_median_dur_by_cat{:});
0382 results.individual_median_dur = individual_median_dur;
0383 results.individual_median_dur_by_cat = individual_median_dur_by_cat;
0384 results.mean_median_dur = nanmean(results.individual_median_dur);
0385 results.mean_median_dur_by_cat = nanmean(results.individual_median_dur_by_cat, 1);
0386 % proportion and frequency are only calculated when individual trial
0387 % time is included in input
0388 if isfield(input, 'individual_range_dur')
0389     range_time_total = nansum(individual_range_dur);
0390     mean_dur_tmp = results.mean_dur;
0391     mean_dur_tmp(isnan(mean_dur_tmp)) = 0;
0392     mean_dur_by_cat_tmp = results.mean_dur_by_cat;
0393     mean_dur_by_cat_tmp(isnan(mean_dur_by_cat_tmp)) = 0;
0394     indiv_mean_dur_tmp = individual_mean_dur;
0395     indiv_mean_dur_tmp(isnan(individual_mean_dur)) = 0;
0396     indiv_mean_dur_by_cat_tmp = individual_mean_dur_by_cat;
0397     indiv_mean_dur_by_cat_tmp(isnan(individual_mean_dur_by_cat)) = 0;
0398     
0399     % proportions
0400     results.prop = mean_dur_tmp * results.total_number / range_time_total;
0401     results.prop_by_cat = mean_dur_by_cat_tmp .* ...
0402         results.total_number_by_cat / range_time_total;
0403     results.individual_prop = (indiv_mean_dur_tmp .* ...
0404         results.individual_number) ./ individual_range_dur;
0405     results.individual_prop_by_cat = (indiv_mean_dur_by_cat_tmp .* results.individual_number_by_cat) ...
0406         ./ repmat(individual_range_dur, 1, length(categories));
0407 
0408     % mean proportions
0409     results.mean_prop = nanmean(results.individual_prop);
0410     results.mean_prop_by_cat = nanmean(results.individual_prop_by_cat, 1);
0411     
0412     % frequency
0413     results.freq = results.total_number / (range_time_total/60);
0414     results.freq_by_cat = results.total_number_by_cat / (range_time_total/60);
0415     results.individual_freq = results.individual_number ./ (individual_range_dur/60);
0416     results.individual_freq_by_cat = results.individual_number_by_cat ...
0417         ./ repmat((individual_range_dur/60), 1, length(categories));
0418     
0419     results.mean_freq = nanmean(results.individual_freq);
0420     results.mean_freq_by_cat = nanmean(results.individual_freq_by_cat, 1);
0421     results.range_time_total = range_time_total;
0422     results.individual_range_dur = individual_range_dur;
0423 end
0424 
0425 % number of switches between categories
0426 individual_switches = cellfun(@(chunk) ...
0427     cevent_number_switches(chunk, categories), ...
0428     chunks, ...
0429     'UniformOutput', false);
0430 individual_switches = vertcat(individual_switches{:});
0431 % results.switches = nansum(individual_switches);
0432 % results.individual_switches = individual_switches;
0433 if isfield(input, 'individual_range_dur')
0434     results.switches_freq = nansum(individual_switches) / (range_time_total/60);
0435     results.individual_switches_freq = individual_switches ./ ...
0436         (input.individual_range_dur/60);
0437 else
0438     results.switches = nansum(individual_switches);
0439     results.individual_switches = individual_switches;
0440 end
0441 
0442 % hist_bins
0443 if isfield(input, 'hist_arg')
0444     hist_arg = input.hist_arg;
0445 else
0446     hist_arg = 'thresholds';
0447 end
0448 
0449 if isfield(input, 'hist_bins')
0450     res_dur_hist = nan(length(chunks), length(input.hist_bins));
0451     for i = 1: length(chunks)
0452         res_dur_hist(i,:) = event_duration_hist(chunks{i}, input.hist_bins, hist_arg);
0453         res_dur_hist(i,:) = res_dur_hist(i,:)/sum(res_dur_hist(i,:));
0454     end
0455        
0456     results.dur_hist = event_duration_hist(cat_chunks, input.hist_bins, hist_arg);
0457     results.dur_hist = results.dur_hist/sum(results.dur_hist);
0458     results.individual_dur_hist = res_dur_hist;
0459 end
0460 
0461 % low shreshold
0462 if isfield(input, 'low_threshold')
0463     res_low_prop = nan(length(chunks), 1);    
0464     for i = 1: length(chunks)
0465         durations_one = chunks{i};
0466         durations_one = durations_one(:,2) - durations_one(:,1);
0467         res_low_prop(i) = sum(durations_one < input.low_threshold) ...
0468             / length(durations_one);
0469     end
0470     
0471     results.dur_low_prop = sum(cat_durations < input.low_threshold) ...
0472         / length(cat_durations);
0473     results.individual_dur_low_prop = res_low_prop;
0474 end
0475 
0476 % high shreshold
0477 if isfield(input, 'high_threshold')
0478     res_high_prop = nan(length(chunks), 1);    
0479     for i = 1: length(chunks)
0480         durations_one = chunks{i};
0481         durations_one = durations_one(:,2) - durations_one(:,1);
0482         res_high_prop(i) = sum(durations_one > input.high_threshold) ...
0483             / length(durations_one);
0484     end
0485     
0486     results.dur_high_prop = sum(cat_durations > input.high_threshold) ...
0487         / length(cat_durations);
0488     results.individual_dur_high_prop = res_high_prop;
0489 end
0490 
0491 % add transition matrix to results
0492 if has_transition_matrix
0493     results.trans_matrix = res_trans_matrix;
0494 %     results.individual_trans_matrix_cell = res_individual_trans_matrix;
0495     
0496     size_trans_matrix = size(res_trans_matrix, 1);
0497     res_tmp_mat_frow = cell(1, size_trans_matrix*size_trans_matrix);
0498     for cfidx = 1:length(categories)
0499         first_num = categories(cfidx);
0500         
0501         for csidx = 1:length(categories)
0502             second_num = categories(csidx);
0503             tmp_str = sprintf('%dto%d', first_num, second_num);
0504             res_tmp_mat_frow{1,(cfidx-1)*length(categories)+csidx} ...
0505                 = tmp_str;
0506         end
0507     end
0508     
0509     res_tmp_mat = zeros(length(chunks), ...
0510         size_trans_matrix*size_trans_matrix);
0511     
0512     for cidx = 1:length(chunks)
0513         tmp_mat = res_individual_trans_matrix{cidx};
0514         tmp_mat = tmp_mat';
0515         res_tmp_mat(cidx,:) = tmp_mat(:)';
0516     end
0517     
0518     results.individual_trans_matrix = ...
0519         vertcat(res_tmp_mat_frow, num2cell(res_tmp_mat));
0520     
0521     if isfield(input, 'individual_range_dur')
0522         res_trans_matrix = res_trans_matrix / (range_time_total/60);
0523     end
0524     results.trans_freq_matrix = res_trans_matrix;
0525     if isfield(input, 'individual_range_dur')
0526         res_tmp_mat = nan(length(chunks), ...
0527             size_trans_matrix*size_trans_matrix);
0528 
0529         for cidx = 1:length(chunks)
0530             tmp_mat = res_individual_trans_freq_matrix{cidx};
0531             res_tmp_mat(cidx,:) = tmp_mat(:)';
0532         end
0533 
0534         results.individual_trans_freq_matrix = ...
0535             vertcat(res_tmp_mat_frow, num2cell(res_tmp_mat));
0536     end
0537 end
0538     
0539 
0540 %% adding the code to replace props and frquency with zeros

Generated on Wed 24-May-2017 00:00:56 by m2html © 2005