Home > database > archived_scripts > extract_panas.m

extract_panas

PURPOSE ^

[panas] = extract_panas(expt, sub_list, resp_table, conn_id)

SYNOPSIS ^

function [panas] = extract_panas(expt, sub_list, resp_table, conn_id)

DESCRIPTION ^

 [panas] = extract_panas(expt, sub_list, resp_table, conn_id)

 Extracts PANAS survey data for a given experiment and list of subjects

 panas.adj - terms in inventory
 panas.data - nsub X nadj X niter matrix, where niter refers to the number of
 times during the experiment that the survey was administered

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [panas] = extract_panas(expt, sub_list, resp_table, conn_id)
0002 % [panas] = extract_panas(expt, sub_list, resp_table, conn_id)
0003 %
0004 % Extracts PANAS survey data for a given experiment and list of subjects
0005 %
0006 % panas.adj - terms in inventory
0007 % panas.data - nsub X nadj X niter matrix, where niter refers to the number of
0008 % times during the experiment that the survey was administered
0009 %
0010 
0011 % 03/04/05 PJ
0012 
0013 global SQL_HOST
0014 
0015 if nargin < 2
0016   sub_list = {};
0017 end
0018 
0019 try conn_id(1);
0020 catch   
0021   mysql_make_conn;
0022   conn_id = 0;
0023 end
0024 
0025 % Identify which form_id is for the PANAS Survey
0026 [form_info{1:2}] = mysql(conn_id,'select form_id, form_name from form');
0027 form_id = form_info{1}(strmatch('PANAS Survey',form_info{2},'exact'));
0028 
0029 
0030 % Get the question IDs that correspond to this form -- in this case a single
0031 % question
0032 quest_id = mysql(conn_id,sprintf('select question_id from form_x_question where form_id=%d',form_id));
0033 
0034 
0035 % Get the list of PANAS adjectives
0036 [panas.adj, sq_id] = mysql(conn_id,sprintf('select heading, subquestion from question_x_data_format where question_id=%d and subquestion>1', quest_id));
0037 
0038 
0039 % Pull all of the data for all of the subjects all at once
0040 extract_vars = {'subject_id', 'form_order', 'subquestion', 'response_enum'};
0041 sql_str = sprintf(['select %s from %s where question_id=%d and subquestion>1'], ...
0042     cell2str(extract_vars,','), resp_table, quest_id);
0043 [panas_resp{1:length(extract_vars)}] = mysql(conn_id,sql_str);
0044 
0045 form_col = strmatch('form_order',extract_vars,'exact');
0046 sq_col = strmatch('subquestion',extract_vars,'exact'); 
0047 resp_col = strmatch('response_enum',extract_vars,'exact');
0048 
0049 % Determine how many times the PANAS was given, and what the form numbers were
0050 iter_ids = unique(panas_resp{form_col});
0051 niter = length(iter_ids);
0052 
0053 % Extract data for each iteration and subject
0054 if isempty(sub_list)
0055   sub_list = unique(panas_resp{1});
0056 end
0057 
0058 nsub_proc = length(sub_list);
0059 panas.subids = sub_list;
0060 panas.data = zeros(nsub_proc,length(sq_id),niter)+NaN;
0061 
0062 for iiter = 1:niter
0063   iter_mask = panas_resp{form_col} == iter_ids(iiter); % iteration mask
0064   for isub = 1:nsub_proc
0065     % Make a mask for this subject
0066     sub_mask = ...
0067     ismember(panas_resp{strmatch('subject_id',extract_vars,'exact')},sub_list{isub});
0068     
0069     % Extract data into final table
0070     curr_idxs = find(iter_mask&sub_mask);
0071     panas.data(isub,panas_resp{sq_col}(curr_idxs)-1,iiter) = log2(panas_resp{resp_col}(curr_idxs));
0072     
0073   end % for isub
0074 end % for iiter
0075 
0076 if ~conn_id
0077   mysql(conn_id,'close')
0078 end
0079 return

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