Home > data-analysis > stats > cstream > cstream_single_stats.m

cstream_single_stats

PURPOSE ^

stats of a cstream variable

SYNOPSIS ^

function [results_all] = cstream_single_stats(input, sub_list2)

DESCRIPTION ^

 
 stats of a cstream variable

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 
0002 %
0003 % stats of a cstream variable
0004 %
0005 
0006 function [results_all] = cstream_single_stats(input, sub_list2)
0007 
0008 exp_ids = input.exp_ids;
0009 var_name = input.var_name;
0010 categories = input.categories; 
0011 local_ids = input.local_ids;
0012 num_valid_value = input.num_valid_value; 
0013 max_gap_btw_event = input.max_gap_btw_event;
0014 dur_hist_bin = input.dur_hist_bin;
0015 % 1 by subjects, 2 by cevent with a certain event value; 3 by event
0016 grouping = input.grouping; 
0017 check_list{1} = var_name; 
0018 
0019 if grouping == 3
0020     event_var_name = input.event_var_name;
0021     check_list = [check_list; event_var_name];
0022 elseif grouping == 2
0023     cevent_var_name = input.cevent_var_name;
0024     cevent_value = input.cevent_value;
0025     check_list = [check_list; cevent_var_name];
0026 end;
0027 
0028 res_trans_mat=zeros(num_valid_value); %
0029 dur_data = [];
0030 for j = 1 : size(categories,2);
0031     dur_data_by_value {j} = []; 
0032 end;
0033 for exp = 1: size(exp_ids,2)
0034     exp_id = exp_ids(exp);    
0035     sub_list= find_subjects(check_list, exp_id); 
0036     sub_list = intersect(sub_list,sub_list2); 
0037     res_hist = [];res_event_number = [];  res_event_dur =[]; res_event_dur_median ...
0038         =[]; num_instance = [];
0039     for i = 1 : size(sub_list,2)
0040         if grouping == 1
0041             [chunks] = get_variable_by_trial(sub_list(i), var_name);
0042         elseif grouping == 2
0043             [chunks] = get_variable_by_cevent(sub_list(i), var_name, cevent_var_name,cevent_value);
0044         elseif grouping == 3
0045             [chunks] = get_variable_by_event(sub_list(i), var_name, event_var_name);
0046         end;
0047         num_instance(i) = size(chunks,1);
0048         if ~isempty(chunks)
0049             cevent = [];
0050             for m = 1 : size(chunks,1)
0051                 cevent = [ cevent; cstream2cevent(chunks{m},1)];
0052             end;
0053             
0054             cstream = cat(1, chunks{:});
0055 
0056             for j = 1 : size(categories,2)
0057                 res_hist(i,j) = size(find(cstream(:,2) == categories(j)),1);
0058                 event =  cevent(cevent(:,3)==categories(j),1:2);
0059                 res_event_number(i,j) = nanmean(size(event,1));
0060                 res_event_dur(i,j) = nanmean(event(:,2)-event(:,1));
0061                 res_event_dur_median(i,j) = nanmedian(event(:,2)-event(:,1));
0062                 dur_data = [ dur_data; event(:,2) - event(:,1)];
0063                 dur_data_by_value{j} = [dur_data_by_value{j}; event(:,2) - ...
0064                                     event(:,1)];
0065                 
0066                 index = find((event(:,2)-event(:,1))>20);
0067                 if ~isempty(index)
0068                     sub_list(i)
0069                     event(index,:)
0070                     categories(j)
0071                 end;
0072             end;
0073             for j = 1 : size(cevent,1)
0074                 try
0075                     cevent(j,3) = local_ids(cevent(j,3)==categories);
0076                 catch exception
0077                     fprintf(1,'there are categories values that are not in the category list %d\n', cevent(j,3));
0078                 end;
0079             end;
0080             res_trans_mat = res_trans_mat + ...
0081                     cevent_transition_matrix(cevent,max_gap_btw_event, num_valid_value);
0082             % normalization
0083             res_hist(i,:) = res_hist(i,:) ./sum(res_hist(i,:));
0084         end;
0085     end;
0086 
0087 
0088     % stats
0089     results.exp_id = exp_id;
0090     results.grouping = grouping;
0091     results.sub_list = sub_list;
0092     results.name = var_name;
0093     results.categories = categories;
0094     results.total_time = mean(res_hist);
0095     results.total_time_hist = res_hist;
0096     results.mean_duration = nanmean(res_event_dur,1);
0097     results.median_duration = nanmean(res_event_dur_median,1);
0098     hist_duration = histc(dur_data,dur_hist_bin)';
0099     results.hist_duration_bin = dur_hist_bin;
0100     results.hist_duration = hist_duration ./sum(hist_duration); 
0101     for j = 1 : size(categories,2)
0102         tmp =  histc(dur_data_by_value{j},dur_hist_bin)';
0103         results.hist_duration_by_value(j,:) = tmp ./sum(tmp);
0104     end;
0105   
0106     for m = 1 : size(num_instance,2)
0107         res_event_number(m,:) = res_event_number(m,:) ./num_instance(m);
0108     end;
0109     results.mean_number = nanmean(res_event_number,1);
0110     results.num_instance = num_instance;
0111     results.transition_matrix = res_trans_mat;
0112     if grouping == 3
0113         results.event_name = event_var_name;
0114     elseif grouping == 2
0115         results.cevent_var_name = cevent_var_name;
0116         results.cevent_value = cevent_value; 
0117     end;
0118     
0119     results_all(exp) = results;
0120 
0121 end;
0122 
0123 
0124 
0125

Generated on Tue 23-May-2017 03:00:58 by m2html © 2005