% HSR/Reading Group, 2/7/2012 C. Scheidiger
clear all;close all

load('DataNSCM/mastconf.mat')
load('DataNSCM/mastconb.mat')
load('DataNSCM/mastvowf.mat')
load('DataNSCM/mastvowb.mat')

% all subjects
child = {'Alina','Angela','Anton','Bob','Carly','Edward','Evan','Joanna','Latisha','Laura','Miguel','Norene','Shauna','Teddy','Tony'};
% subjects that belong to the control group
child_n = {'Anton','Bob','Carly','Evan','Joanna', 'Miguel'};
idx_n = [];
idx_d = [];
for sbj=1:length(child)
    if ~isempty(find(strcmp(child{sbj},child_n)))
        idx_n = [idx_n sbj]
    else
        idx_d = [idx_d sbj]
    end
end

%mastconf() contains the scores
%Each row is a child (1:15)
%Each Column (1:25) contains the number of correct responses
%Each Column (26:50) contains the number of trials

%sum of sum of correct answers devided by sum of presentations
con(1 , 1:15, 1:25) = mastconf(1:15,1:25);
con(2 , 1:15, 1:25) = mastconb(1:15,1:25);
con_N(1 , 1:15, 1:25) = mastconf(1:15,26:50);
con_N(2 , 1:15, 1:25) =  mastconb(1:15,26:50);

vow(1 , 1:15, 1:15) = mastvowf(1:15,1:15);
vow(2 , 1:15, 1:15) = mastvowb(1:15,1:15);
vow_N(1 , 1:15, 1:15) = mastvowf(1:15,16:30);
vow_N(2 , 1:15, 1:15) = mastvowb(1:15,16:30);

Pe_vow = 1-vow./vow_N;
Pe_con = 1-con./con_N;

% con
for pos=1:2 % selects postion (initial, final)
    for nd=1:2  % selects group of childern (disabled, or normal) 
        if nd == 1
            idx = idx_n;
            if pos ==1
                linetype = '-xb';
                plt_pos = 1;
                plt_title = 'NR Consonants_{initial} '
            else
                linetype = '--xb';
                plt_pos = 3;
                plt_title = 'NR Consonants_{final} '
            end
        else
            idx = idx_d;
            if pos ==1
                linetype = '-r';
                plt_pos = 2;
                plt_title = 'RD Consonants_{initial} '
            else
                linetype = '--r';
                plt_pos = 4;
                plt_title = 'RD Consonants_{final} '
            end
        end
        for subj=1:length(idx)
            % child{idx(subj)}
            % squeeze( con( pos , idx(subj), : ) )
            pe = squeeze( Pe_con( pos , idx(subj), : ) );
            % remove H
            pe = [pe(1:3) ; pe(5:length(pe))];
            pe_sorted = sort( pe );
            subplot(2,2,plt_pos)
            plot(pe_sorted,cumsum(pe_sorted), linetype)
            set(gca, 'FontSize', 16);
            ylim([0 6]);
            xlim([0 1]);
            title( plt_title );
            grid on
            hold on
        end
    end
end

subplot(221); ylabel('\int_0^{Pe}P_e dx');
subplot(223); ylabel('\int_0^{Pe}P_e dx');
subplot(223); xlabel('P_e');
subplot(224); xlabel('P_e');

print -depsc2 cmdata


