Load Demo data

load('Demo_Y_Ypred.mat'); in F:\Stat_Math\NewThingsA_O\Magalie_CB

Contents

-1/+1

X contains -1/+1 Size oof X

[nXr,nXc]=size(X);

% Sample numbers
Samples_Nums=[1:nXr]';

% Sample names
Samples=num2str(Samples_Nums);

% Variable names
X_Vars=num2str([1:nXc]');

% Nb of blocks= Nb of variables
nXBlocks=nXc;
% X Block numbers
XBlocks_Nums=[1:nXBlocks]';

% Nb of Common Components
CCs=4;

Create data collection for ComDim analysis

clear collection;

% One X variaable per Block
for i=1:nXBlocks
    collection(i).d=X(:,i);
    collection(i).i=[1:nXr];
    collection(i).v=i;
end

% Then add one Y variaable per Block
collection(nXBlocks+1).d=y;
collection(nXBlocks+1).i=1;
collection(nXBlocks+1).v=1;

% Total Nb of X & Y blocks
nBlocks=nXBlocks+1;

% Total X & Y Block numbers
Blocks_Nums=[1:nBlocks]';
[MyResult]=comdim_calib_V6(collection,CCs);

Plot ComDim global Scores

figure;
for i=1:CCs
    subplot(2,2,i);
    stem(Samples_Nums,MyResult.Q.d(:,i),'FaceColor','b'), axis tight;
    text(Samples_Nums,MyResult.Q.d(:,i),Samples);
    xlabel('Samples');
    ylabel(['CC Scores ', num2str(i)]);
end;

Plot ComDim X & Y Saliences

figure;
for i=1:CCs
    subplot(2,2,i);
    stem(Blocks_Nums,MyResult.saliences.d(:,i),'FaceColor','k'), axis tight;
    hold on;

    % Plot Salience for Y block
    stem(Blocks_Nums(end),MyResult.saliences.d(end,i),'FaceColor','r'), axis tight;
    text(XBlocks_Nums,MyResult.saliences.d(1:end-1,i),X_Vars,'FontSize',7), axis tight;
    xlabel('Data block');
    ylabel(['CC Salience', num2str(i)]);
    ylim([0,1]);
end;

Plot ComDim Global Scores for CC1

figure;
stem(Samples_Nums,MyResult.Q.d(:,1),'FaceColor','b'), axis tight;
text(Samples_Nums,MyResult.Q.d(:,1),Samples);
xlabel('Samples');
ylabel('Scores');
title(['CC' num2str(1)]);

Plot ComDim X & Y Loadings for CC1

figure;
stem(Blocks_Nums,MyResult.saliences.d(:,1),'FaceColor','k'), axis tight;
hold on;

% Plot CC1 Salience for Y block
stem(Blocks_Nums(end),MyResult.saliences.d(end,1),'FaceColor','r'), axis tight;
text(XBlocks_Nums,MyResult.saliences.d(1:end-1,1),X_Vars,'FontSize',7), axis tight;
xlabel('Data block');
ylabel('Salience');
ylim([0,1]);
title(['CC' num2str(1)]);

Plot ComDim Saliences & Loadings for X on CC1

figure;
subplot(2,1,1);
stem(XBlocks_Nums,MyResult.saliences.d(1:end-1,1),'FaceColor','k'), axis tight;
xlabel('Data block');
ylabel('Salience');
title(['CC' num2str(1)]);

subplot(2,1,2);
stem(XBlocks_Nums,MyResult.P.d(1:end-1,1),'FaceColor','m'), axis tight;
xlabel('Data block');
ylabel('Loadings');

Mean center Y

y_cent=y-mean(y);

Calculate Y pred from X and X-loadings

y_pred=X*MyResult.P.d(1:end-1,1);

figure;
plot(y_cent,y_pred,'bo');
xlabel('Observed Y');
ylabel('Predicted Y');