Home > database > ensemble_get_student_id.m

ensemble_get_student_id

PURPOSE ^

returns unique student id/subject id combinations found in response data

SYNOPSIS ^

function outdata = ensemble_get_student_id(indata,params)

DESCRIPTION ^

 returns unique student id/subject id combinations found in response data
 
   outdata = ensemble_get_student_id(indata,params)
 
 given an ensemble data struct containing response table data, this
 function will find all unique combinations of subject_id and student_id,
 and will return these in an ensemble data struct.
 
 REQURIES
   indata - ensemble data struct containing response table data (see
       ensemble_load_expinfo)
   params.student_id_qid (default: 558) - question id containing a
       participant's student_id
 
 FB 2009.05.16

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function outdata = ensemble_get_student_id(indata,params)
0002 
0003 % returns unique student id/subject id combinations found in response data
0004 %
0005 %   outdata = ensemble_get_student_id(indata,params)
0006 %
0007 % given an ensemble data struct containing response table data, this
0008 % function will find all unique combinations of subject_id and student_id,
0009 % and will return these in an ensemble data struct.
0010 %
0011 % REQURIES
0012 %   indata - ensemble data struct containing response table data (see
0013 %       ensemble_load_expinfo)
0014 %   params.student_id_qid (default: 558) - question id containing a
0015 %       participant's student_id
0016 %
0017 % FB 2009.05.16
0018 
0019 % init vars
0020 outdata = ensemble_init_data_struct();
0021 outdata.name = 'student_ids';
0022 outdata.type = 'student_ids';
0023 outdata.vars = {'subject_id','student_id'};
0024 outdata.data = {{} {}};
0025 ocol = set_var_col_const(outdata.vars);
0026 
0027 % check structure of indata
0028 incol = set_var_col_const(indata.vars);
0029 if ~isfield(incol,'subject_id'), error('no subid found within indata'); end
0030 if ~isfield(incol,'response_text'), error('response text not found'); end
0031 
0032 % get student_ids
0033 if isfield(params,'student_id_qid') && ~isempty(params.student_id_qid)
0034   siqid =  params.student_id_qid;
0035 else
0036   siqid =  558;
0037 end
0038 filt.include.all.question_id = siqid
0039 indata = ensemble_filter(indata,filt);
0040 
0041 % check for rows
0042 if isempty(indata.data{1})
0043   error('no student IDs (question %d) found in the given dataset',siqid);
0044 end
0045 
0046 % find unique subjects
0047 [sm,us] = make_mask_mtx(indata.data{incol.subject_id});
0048 ns = length(us);
0049 if any(sum(sm) > 1), warning('multiple records for some subjects'); end
0050 
0051 % iterate over subjects, find student_id
0052 for is=1:ns
0053   subid = us{is};
0054   sids = indata.data{incol.response_text}(sm(:,is));
0055   if length(sids) > 1
0056     warning('multiple student ids found for %s, taking first',subid);
0057     sids = sids(1);
0058   end
0059   outdata = ensemble_add_data_struct_row(outdata,'subject_id',subid,...
0060       'student_id',sids);
0061 end

Generated on Wed 20-Sep-2023 04:00:50 by m2html © 2003