function  plot_PLM_fit2a(mZcongr,hZcongr)

%PLOT_PLM_FIT2 -- Plot the PLExp2 z-probability curves for PLM_Hebb2.
%   
%  plot_PLM_fit2a(mZcongr)
%  plot_PLM_fit2a(mZcongr,hZcongr)
%
%  MZCONGR is model data as produced by PLM_ZCONGR2 (6x36 matrix).
%  The rows (or "conditions") in ZCONGR have the following indices:
%   1: congruent Gabor, contrast 0.23
%   2: incongruent Gabor, contrast 0.23
%   3: congruent Gabor, contrast 0.15
%   4: incongruent Gabor, contrast 0.15
%   5: congruent Gabor, contrast 0.10
%   6: incongruent Gabor, contrast 0.10
%  HZCONGR is the human data. When not supplied, it defaults to
%  the global variable HUMAN_ZCONGR. Pass [] to prevent comparison 
%  with HUMAN_ZCONGR altogether.
%
%  See also PLOT_PLM_FIT, PLM_ZCONGR2, PLOT_PLM_DYNAMICS.

%  Original coding by Alexander Petrov, UC Irvine.
%  $Revision: 1.0 $  $Date: 2005/07/01 11:03 $

global HUMAN_ZCONGR

if (nargin==1)  hZcongr = HUMAN_ZCONGR ; end   % default

if (iscell(mZcongr))         % {sumstats.zP_congr',sumstats.zP_incon'}
   mZcongr = cat(1,mZcongr{:}) ;
   mZcongr([2,3,4,5],:) = mZcongr([4,2,5,3],:) ;
end

if (isempty(hZcongr))
   hZcongr_p = 0 ;
   hZcongr = mZcongr ;
else
   hZcongr_p = 1 ;
end

blocks = {[1],[2:9],[10:17],[18:25],[26:33],[34:36]} ;
N_blocks = length(blocks) ;
xtick = [0:4:36] ;
colors = {'b','r','g'} ; markers = {'^','o','s'} ;

%-- Plot ZCONGR curves for the congruent stimuli
E = sum(sum((mZcongr([1 3 5],:)-hZcongr([1 3 5],:)).^2)) ;
subplot(3,1,1) ; cla ; hold on ;
%figure ; hold on ;
for c = 1:3
   mstyle = [colors{c},markers{c},'-'] ;    % e.g. 'r^-'
   hstyle = [colors{c},'.--'] ;             % e.g. 'r.:'
   for k = 1:N_blocks
      idx = blocks{k} ;
      plot(idx,mZcongr(2*c-1,idx),mstyle) ;
      if (hZcongr_p)  plot(idx,hZcongr(2*c-1,idx),hstyle) ; end
   end
end
axis([0 37 0 2.5]) ; set(gca,'xtick',xtick) ; box on ; grid on ;
ylabel('\Phi^{-1}(Pcorr)') ;  hold off ;
if (hZcongr_p)
   title(sprintf('Congruent stimuli: Pcorrect by contrast,  E=%5.2f',E)) ;
else
   title('Congruent stimuli: Pcorrect by contrast') ;
end

%-- Plot ZCONGR curves for the incongruent stimuli
E = sum(sum((mZcongr([2 4 6],:)-hZcongr([2 4 6],:)).^2)) ;
subplot(3,1,2) ; cla ; hold on ;
%figure ; hold on ;
for c = 1:3
   mstyle = [colors{c},markers{c},'-'] ;    % e.g. 'r^-'
   hstyle = [colors{c},'.--'] ;              % e.g. 'r.:'
   for k = 1:N_blocks
      idx = blocks{k} ;
      plot(idx,mZcongr(2*c,idx),mstyle) ;
      if (hZcongr_p)  plot(idx,hZcongr(2*c,idx),hstyle) ; end
   end
end
axis([0 37 -2.5 0]) ; set(gca,'xtick',xtick) ; box on ; grid on ;
ylabel('\Phi^{-1}(Pcorr)') ;  hold off ;
if (hZcongr_p)
 title(sprintf('Incongruent stimuli: Pcorrect by contrast,  E=%5.2f',E)) ;
else
   title('Incongruent stimuli: Pcorrect by contrast') ;
end


%-- Plot D-PRIMES curves for each contrast level
mdpr = (mZcongr([1 3 5],:) + mZcongr([2 4 6],:)) ./ 2 ;
hdpr = (hZcongr([1 3 5],:) + hZcongr([2 4 6],:)) ./ 2 ;
E = sum(sum((mdpr-hdpr).^2)) ;
subplot(3,1,3) ; cla ; hold on ;
%figure ; hold on ;
for c = 1:3
   mstyle = [colors{c},markers{c},'-'] ;    % e.g. 'r^-'
   hstyle = [colors{c},'.--'] ;             % e.g. 'r.:'
   for k = 1:N_blocks
      idx = blocks{k} ;
      plot(idx,mdpr(c,idx),mstyle) ;
      if (hZcongr_p)  plot(idx,hdpr(c,idx),hstyle) ; end
   end
end
axis([0 37 -.1 1.5]) ; set(gca,'xtick',xtick,'ytick',[0:.25:1.5]) ;grid on;
ylabel('d''/2') ; hold off ; box on ;
if (hZcongr_p)
   title(sprintf('D-prime profiles by contrast,  E=%5.2f',E)) ;
else
   title('D-prime profiles by contrast') ;
end

%%%%% End of file PLOT_PLM_FIT2.M
