function  [estats,descr,resp] = PLEstats_by_sbj(S)

%PLESTATS_BY_SBJ -- Aggregate statistics, PLExp1 data by sbj.
%
% S = PLEdata_by_sbj ; estats = PLEstats_by_sbj(S)
% esumstats = PLM_summary(estats) ; plot_PLM_dynamics(esumstats) ;
%   estats = 
%       group: [13x1 double]
%    zP_congr: [32x3x13 double]
%    zP_incon: [32x3x13 double]
%      dprime: [32x3x13 double]
%       accZP: [13x6 double]
%    contextc: [13x20 double]
%    contexti: [13x20 double]
%      otherc: [13x20 double]
%      otheri: [13x20 double]
%
% See function PLModel1\simul\PLM_stats.m  for details.
% 
% See also PLM_STATS, PLM_SUMMARY, PLEDATA_BY_SBJ, PLMTRANS_BY_SBJ.

% Original coding by Alexander Petrov, UC Irvine.
% $Revision: 1.0 $  $Date: 2003/03/10 08:58 $

%-- Recode the data into "descriptor" format (cf. BLOCK_FROM_CACHE)
N_sbj = length(S) ;
descr = zeros([9600,3,N_sbj]) ;
resp = zeros([9600,N_sbj]) ;
for k = 1:length(S)
   d = S(k).data(:,[5,3,2,7]) ;    % [Gabor_orient,Cpeak,noise_orient,resp]
   d(S(k).miss_idx,:) = [] ;       % [9600x4]
   %- Gabor orient: [-10,+10]-->[1,2]
   descr(:,1,k) = d(:,1)./20 + 1.5 ;
   %- Peak contrast Cp: [0.23,0.15,0.10]-->[1,2,3]
   Cp = d(:,2) ;
   Cp(find(Cp==0.23)) = 1 ;
   Cp(find(Cp==0.15)) = 2 ;
   Cp(find(Cp==0.10)) = 3 ;
   descr(:,2,k) = Cp ;
   %- noise orient: [-15,+15]-->[1,2]
   descr(:,3,k) = d(:,3)./30 + 1.5 ;
   %- response: 1="Left",2="Right", there shouldn't be any more 0="Miss"
   resp(:,k) = d(:,4) ;
end

estats = PLM_stats(descr,resp) ;

%--- Return ESTATS  (and possibly DESCR and RESP)
%%%%% End of PLESTATS_BY_SBJ.M
