 %Performs prediction using calibration data saved in trainedModel 
%********************************************************************************

close all;
xtest=x1dc10n;
ytest=y110;
xtest=xcal4;
ytest=ycal4;

p=6;

v=[];
u=[];
w=[];

for ip=1:length(ytest)
v(ip,:) = xtest(ip,:); %select x spectra data to use for prediction
u(ip) = ytest(ip);; %select y glucose data to use for error calculation if available
%u(ip)=u(ip)';
trainedModel = TMcal64 %select calibration model
w(ip) = trainedModel.predictFcn(v(ip,:));
%RDp(ip) = 100*(avp(w(ip),6))/avp(u(ip),6)-1);
end

MARDprd = 100*mean(abs(avp(w,p)./avp(u,p)-1));

%figure 1
w=w';
[totalClark, percentClark] = clarke(u,w);

%figure 2
%mdlpred = fitlm(w,u); %returns a linear regression model of the responses y, fit to the data matrix X.
%anova(mdlpred,'summary'); %test fit by anova
%figure;plot(mdlpred)
%title('mdle2 pred')

%figure 3;
[N M] = size(w);
m=[1:N];
m=m';
figure; plot(m,u,'-ro',m,w,'-bo')

%************************************************************************
%Fig6
%figure;plot(m,uavg,'-ro',m,wavg,'-bo')
%title('Prediction'); xlabel('Record Number]'); ylabel('Concentration [mg/dL]');
%legend('Reference', 'Predicted');

%uavg = avp(u',p);
%wavg = avp(w,p); 
%[N2 M2] = size(uavg);
%m=[1:N2];

%Fig4
%[totalClark, percentClark] = clarke(uavg,wavg);

%Fig5
%mdlpred = fitlm(uavg,wavg); %returns a linear regression model of the responses y, fit to the data matrix X.
%anova(mdlpred,'summary'); %test fit by anova
%figure;plot(mdlpred);title('mdle2 pred')
%************************************************************************

save('prd_d1r0c0sUnivDCPam2_EGPR64');
