Home > data-utility > main_check_variables.m

main_check_variables

PURPOSE ^

SYNOPSIS ^

function [] = main_check_variables(sub_list, data_types, is_to_display, dir_name)

DESCRIPTION ^

 this function performs data validation by checking several properties
 of the four data types. It goes through all the variables one by one
 and generate a report which will be either displayed (is_to_display =
 1) or saved in  a set of report files (e.g. cstream_check_1401). In the
 later case, dir_name specifies the directory to save those files. 
    
 e.g.    
dir_name = '/ein/scratch/Zeth/variable_check';
sub_list = [1401:1418];
data_types = {'event_','cont_','cevent_','cstream_'}; 
is_to_display = 0;  % 1 -- display; 0 - to a file
 then call this function 
   main_check_variables(sub_list, data_types, is_to_display, dir_name)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 
0002 function [] =  main_check_variables(sub_list, data_types, is_to_display, dir_name)
0003 %
0004 % this function performs data validation by checking several properties
0005 % of the four data types. It goes through all the variables one by one
0006 % and generate a report which will be either displayed (is_to_display =
0007 % 1) or saved in  a set of report files (e.g. cstream_check_1401). In the
0008 % later case, dir_name specifies the directory to save those files.
0009 %
0010 % e.g.
0011 %dir_name = '/ein/scratch/Zeth/variable_check';
0012 %sub_list = [1401:1418];
0013 %data_types = {'event_','cont_','cevent_','cstream_'};
0014 %is_to_display = 0;  % 1 -- display; 0 - to a file
0015 % then call this function
0016 %   main_check_variables(sub_list, data_types, is_to_display, dir_name)
0017 
0018 for s = 1 : size(sub_list,2)
0019     subject = sub_list(s)
0020     for d  = 1 : size(data_types,2)
0021         data_type = data_types{d};
0022         listing = list_variables(subject); 
0023         
0024         if is_to_display ==1
0025             io = 1; 
0026         else
0027             file_name = sprintf('%s/%scheck_%d.txt',dir_name,data_type, subject);
0028             fid = fopen(file_name,'w');
0029             io = fid; 
0030         end;
0031         for i = 1 : size(listing,1)
0032             variable_name = listing{i};
0033             switch data_type 
0034               
0035               case 'cont_'
0036                 if sum(strfind(variable_name, data_type)) > 0
0037                     data = get_variable(subject,variable_name); 
0038                     fprintf(io, ['***************************************' ...
0039                                  '*******\n']);
0040                     fprintf(io,'%s\n',variable_name);
0041                     
0042                     fprintf(io, ['%s\nmean:%5.2f, median:%5.2f, SD:%5.2f, ' ...
0043                                'min:%5.2f, max: %5.2f\n'],variable_name, mean(data(:,2)), median(data(:,2)),std(data(:,2)),min(data(:,2)),max(data(:,2)));
0044                   
0045                     bin_edge = linspace(min(data(:,2)), max(data(:,2)),10);
0046                     hist_data = histc(data(:,2),bin_edge) ./size(data,1);
0047                     fprintf(io,'bin: '), fprintf(io, '%5.2f ', bin_edge); fprintf(io,'\n');
0048                     fprintf(io, 'prop:'); fprintf(io,'%5.2f ', hist_data);
0049                     fprintf(io, '\n**********************************************\n\n');
0050                 end;
0051                 
0052               case  'cstream_'
0053                 if sum(strfind(variable_name, data_type)) > 0
0054                     data = get_variable(subject,variable_name); 
0055                     item_list = unique(data(:,2));
0056                     num_item = []; 
0057                     for n_item = 1 : size(item_list,1)
0058                         num_item(n_item) = size(find(data(:,2) == item_list(n_item)),1)/size(data,1);
0059                     end;
0060                     fprintf(io, '**********************************************\n');
0061                     fprintf(io,'%s\n',variable_name);
0062                     fprintf(io, 'categories:');fprintf(io, '%5d ', item_list); fprintf(io,'\n');
0063                     fprintf(io, '      prop:');fprintf(io, '%5.2f ', ...
0064                                                        num_item); ...
0065                         fprintf(io,'\n');
0066                     
0067                     fprintf(io, '# of switches:%5d\n',size(find(diff(data(:,2) ~=0)),1));
0068                     fprintf(io, '\n**********************************************\n\n');
0069                 end;
0070             
0071               case  'cevent_'
0072                 if sum(strfind(variable_name, data_type)) > 0
0073                     data = get_variable(subject,variable_name); 
0074                     item_list = unique(data(:,3));
0075                     num_item = []; mean_dur_item = []; median_dur_item = ...
0076                         [];
0077                     min_dur_item = []; max_dur_item = [];
0078                     
0079                     for n_item = 1 : size(item_list,1)
0080                         index = find(data(:,3) == item_list(n_item));
0081                         num_item(n_item) = size(index, 1);    
0082                         all_duration = data(index,2) - data(index,1); 
0083                         mean_dur_item(n_item) = mean(all_duration);
0084                         median_dur_item(n_item) = median(all_duration);
0085                         min_dur_item(n_item) = min(all_duration);
0086                         max_dur_item(n_item) = max(all_duration);
0087                     end;
0088                     fprintf(io, '**********************************************\n');
0089                     fprintf(io,'%s\n',variable_name);
0090                     fprintf(io, ' # of cevents: %d\n', size(data,1));
0091                     fprintf(io, '   categories:');fprintf(io, '%6d ', ...
0092                                                           item_list); fprintf(io,'\n');
0093                     fprintf(io, '# of switches:');fprintf(io, '%6.2f ', num_item); fprintf(io,'\n');
0094 
0095                     fprintf(io, 'mean duration:');fprintf(io, '%6.2f ', ...
0096                                                           mean_dur_item); fprintf(io,'\n');                   
0097                     fprintf(io, 'med  duration:');fprintf(io, '%6.2f ', median_dur_item); fprintf(io,'\n');
0098                     fprintf(io, 'min  duration:');fprintf(io, '%6.2f ', min_dur_item); fprintf(io,'\n');
0099                     fprintf(io, 'max  duration:');fprintf(io, '%6.2f ', max_dur_item); fprintf(io,'\n');
0100 
0101                     fprintf(io, '\n**********************************************\n\n');
0102                 end;
0103             
0104                 case  'event_'
0105                 if sum(strfind(variable_name, data_type)) > 0 && ...
0106                         sum(strfind(variable_name,'cevent_')) == 0
0107                     data = get_variable(subject,variable_name);
0108                     all_duration = data(:,2) - data(:,1); 
0109                     fprintf(io, '**********************************************\n');
0110                     fprintf(io,'%s\n',variable_name);
0111                     fprintf(io, ' # of cevents: %d\n', size(data,1));
0112                     fprintf(io, [' duration, mean:%6.2f, median:%6.2f; ' ...
0113                                  'min:%6.2f,max:%6.2f'], mean(all_duration), ...
0114                             median(all_duration), min(all_duration), max(all_duration));
0115                     fprintf(io, '\n**********************************************\n\n');
0116 
0117                 end;
0118                 
0119             end;
0120         end;
0121         
0122         if is_to_display == 0
0123             fclose(io); 
0124         end;
0125     end;
0126 end;

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