% This program is used to generate scatter plots for consonants and vowels in initial versus final position. The control group is highlighted 
% with red dots while the reading impaired group has blue dots. I usually put in the 45 degree line externally.

clear all;close all

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

child={'Alina','Angela','Anton','Bob','Carly','Edward','Evan','Joanna','Latisha','Laura','Miguel','Norene','Shauna','Teddy','Tony'};

%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

conf=1-(sum(mastconf(1:15,1:25),2)./sum(mastconf(1:15,26:50),2));
conb=1-(sum(mastconb(1:15,1:25),2)./sum(mastconb(1:15,26:50),2));
vowf=1-(sum(mastvowf(1:15,1:15),2)./sum(mastvowf(1:15,16:30),2));
vowb=1-(sum(mastvowb(1:15,1:15),2)./sum(mastvowb(1:15,16:30),2));

%      1     2 3     4     5         6 7     8         9    10 11       12    13    14    15  
C=[0 0 1;0 0 1;1 0 0;1 0 0;1 0 0;0 0 1;1 0 0;1 0 0;0 0 1;0 0 1;1 0 0;0 0 1;0 0 1;0 0 1;0 0 1];
D=[1:2  6  9:10 12:15]; %Deficient readers
N=[3:5 7:8 11] ; %Normal readers 

fig(1);

%scatter(conf,conb,25,C,'filled')
plot(conf(D),conb(D),'rs','MarkerSize',14,'LineWidth',3); hold on;
plot(conf(N),conb(N),'bo','MarkerSize',14,'LineWidth',3);
plot([0 0.5],[0 0.5],':')
xlabel('Vowel error in initial position')
ylabel('Vowel error in final position')
title('Scatter plots for vowel errors in initial versus final position')
xlim([0.05 .3]); ylim([0.05 .3])
grid
hold off

dx=0.0025; dy=-dx/2;
for i=1:15
    text(dx+conf(i,1),dy+conb(i,1),child{1,i},'FontSize',14)
end    
print -dpng 'ViVf'

fig(2);

%scatter(vowf,vowb,25,C,'filled')
plot(vowf(D),vowb(D),'rs','MarkerSize',14,'LineWidth',3); hold on;
plot(vowf(N),vowb(N),'bo','MarkerSize',14,'LineWidth',3);
plot([0 0.5],[0 0.5],':')
xlim([0.05 .3]); ylim([0.05 .3]);
grid;
hold off
xlabel('Consonant error in initial position')
ylabel('Consonant error in final position')
title('Scatter plots for consonant errors in initial versus final position')

for i=1:15
    text(vowf(i,1),vowb(i,1),child{1,i})
end
print -dpng 'CiCf'

break

fig(3); %Initial vowel vs consonant error

%scatter(vowf,vowb,25,C,'filled')
%plot(conb(D),vowb(D),'bo','MarkerSize',14,'LineWidth',3); hold on;
%plot(conb(N),vowb(N),'rx','MarkerSize',14,'LineWidth',3);
%xlabel('Consonant error in final position')
%ylabel('Vowel error in final position')
%title('Scatter plots for consonant errors in initial versus vowel in final position')

plot(conf(D),vowf(D),'rs','MarkerSize',14,'LineWidth',3); hold on;
plot(conf(N),vowf(N),'bo','MarkerSize',14,'LineWidth',3);
plot([0 0.5],[0 0.5],':')
xlim([0.05 .3]); ylim([0.05 .3]); grid;
hold off
xlabel('Consonant error in final position')
ylabel('Vowel error in final position')
title('C_f versus V_f','FontSize',18)

dx=0.003; dy=-dx/2;
for i=1:15
    text(dx+conf(i,1),dy+vowf(i,1),child{1,i},'FontSize',12)
end
print -dpng 'CfVf'
