forked from mwgeurts/libra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeplot.m
executable file
·1501 lines (1480 loc) · 61.9 KB
/
makeplot.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function makeplot(out,varargin)
%MAKEPLOT makes plots for the main functions. These figures can also be obtained
% by setting 'plots = 1' in those functions.
%
% Required input:
% out = a structure containing the output of one of the following classes:
% MCDCOV, LS, LTS, MLR, MCDREG, CPCA,CPCR, CSIMPLS, RAPCA, ROBPCA,
% RPCR, RSIMPLS, CDA, RDA, PAM, AGNES, DIANA, FANNY, MONA, CLARA
%
% Optional input:
% nameplot : 0 : menu of plots (default = 0)
% 'all' : all possible plots
% 'scree' : scree plot
% 'pcadiag' : Score outlier map
% 'regdiag' : Regression outlier map
% '3ddiag' : 3D Regression outlier map
% 'robdist' : A plot of the robust distances
% 'qqmcd' : A qq-plot of the robust distances versus the quantiles of the chi-squared distribution
% 'dd' : A DD-plot: Robust distances versus Mahalanobis distances
% 'ellipse' : A tolerance ellipse
% 'resfit' : Standardized LTS Residuals versus fitted values
% 'resindex' : Standardized LTS Residuals versus index
% 'qqlts' : Normal QQ-plot of the LTS residuals
% 'scatter' : Scatterplot with LTS line
% 'da' : Tolerance ellipses of a discrimant analysis
% 'simca' : Scatterplot with boundaries defined by the number of PC's from a simca method
% 'tree' : Tree plot for the clustering methods agnes or diana
% 'silhouet' : Silhouette plot for the clustering methods pam or fanny
% 'banner' : Banner for the clustering methods agnes, diana or mona
% 'clus' : Clusplot for the clustering methods clara, fanny or pam
% labod : number of points to be identified in score plots
% with largest orthogonal distance.
% labsd : number of points to be identified in score and regression plots
% with largest score distance.
% labresd : number of points to be identified in regression plots
% with largest residual distance.
% labmcd : number of points to be identified in MCD plots
% with the largest robust distance.
% lablts : number of points to be identified in LTS plots
% with the largest absolute standardized residual.
% classic : In case of a robust analysis, classic can be set to 0 to avoid classical plots (default).
% If set to one, the inputargument 'out' must contain a field called 'classic' which is a structure.
%
% I/O: makeplot(out,'nameplot',0,'labsd',3,'labod',3,'labresd',3,'classic',0)
% The user should only give the input arguments that have to change their default value.
% The name of the input arguments needs to be followed by their value. The order of
% the input arguments is of no importance.
%
% Example: outrpcr=rpcr(x,y,'plots',0,'classic',1);
% makeplot(outrpcr,'labsd',5, 'classic',1)
% makeplot(outrpcr,'nameplot','scree')
%
% outmcd=mcdcov(x);
% makeplot(outmcd,'labmcd',6)
% makeplot(outmcd,'labmcd',4,'nameplot','dd')
%
% outls=ols(x,y);
% makeplot(outls)
%
% This function is part of LIBRA: the Matlab Library for Robust Analysis,
% available at:
% http://wis.kuleuven.be/stat/robust.html
%
% Written by Sabine Verboven 09/04/2003
% Last Updated : 29/01/2008
%
% Uses functions: screeplot, scorediagplot, regresdiagplot,
% regresdiagplot3d, plotnumbers, plotnumbers3d,
% distplot, chiqqplot, ddplot, ellipsplot, residualplot,
% normqqplot, lsscatter, tree, bannerplot,
% silhouetteplot, clusplot,
% menureg, menuscoreg, menupls, menucov, menuls,menuda,
% menusimca, menuclus1, menuclus2, menuclus3, menuclus4
%
%INTITIALISATION%
if isstruct(out)
innames=fieldnames(out);
if strmatch('class',innames,'exact')
attrib=out.class;
else
error('The method had no class identifier.')
end
if strmatch('classic',innames,'exact')
classic=out.classic;
elseif ismember(attrib,{'CPCA','CPCR','CSIMPLS','MLR','CDA','LS','CSIMCA'})
classic= 1;
else
classic=0;
end
else
error('The first inputargument is not a structure.')
end
counter=1;
default=struct('nameplot',0,'labsd',3,'labod',3,'labresd',3,'labmcd',3,'lablts',3,'labclus',[],'classic',1);
list=fieldnames(default);
options=default;
IN=length(list);
i=1;
%
if nargin>1
%
%placing inputfields in array of strings
%
for j=1:nargin-1
if rem(j,2)~=0
chklist{i}=varargin{j};
i=i+1;
end
end
%
%Checking which default parameters have to be changed
% and keep them in the structure 'options'.
%
while counter<=IN
index=strmatch(list(counter,:),chklist,'exact');
if ~isempty(index) %in case of similarity
for j=1:nargin-2 %searching the index of the accompanying field
if rem(j,2)~=0 %fieldnames are placed on odd index
if strcmp(chklist{index},varargin{j})
I=j;
end
end
end
options=setfield(options,chklist{index},varargin{I+1});
index=[];
end
counter=counter+1;
end
choice=options.nameplot;
if choice~=0
ask=0;
else
ask=1; %menu of plots
end
labsd=options.labsd;
labod=options.labod;
labresd=options.labresd;
labmcd=options.labmcd;
lablts=options.lablts;
labclus=options.labclus;
classicplots=options.classic;
if ~isstruct(classic) & options.classic==1 & ismember({attrib},{'RAPCA', 'ROBPCA', 'RPCR', 'LTS', 'MCDREG',...
'RSIMPLS', 'RDA', 'RSIMCA'})
mess=sprintf(['The classical output is not available. Only robust plots will be shown.\n',...
'Please rerun the preceeding analysis with the option ''classic'' set to 1',...
'\n if the classical plots are required.']);
disp(mess)
classicplots=0;
end
else
ask=1; %menu of plots
choice=0;
labsd=3;
labod=3;
labresd=3;
labmcd=3;
lablts=3;
labclus=[];
if ~isstruct(classic) & options.classic==1 & ismember({attrib},{'RAPCA', 'ROBPCA', 'RPCR', 'LTS', 'MCDREG',...
'RSIMPLS', 'RDA', 'RSIMCA','MCDCOV'})
mess=sprintf(['The classical output is not available. Only robust plots will be shown.\n',...
'Please rerun the preceeding analysis with the option ''classic'' set to 1',...
'\n if the classical plots are required.']);
disp(mess)
classicplots=0;
else
classicplots=1;
end
end
%to initialize the correct menu of plots
exitno=0;
switch attrib
case 'CPCA'
exitno=4;
if ismember({char(choice)},{'regdiag','3ddiag','robdist','qqmcd','dd','ellipse','resfit','resindex','qqlts','diag','scatter',...
'da','simca'})
error('That kind of plot is not available for this method.')
end
case 'CPCR'
exitno=6;
if ismember({char(choice)},{'robdist','qqmcd','dd','ellipse','resfit','resindex','qqlts','diag','scatter','da','simca'})
error('That kind of plot is not available for this method.')
end
case 'LS'
exitno=7;
if ismember({char(choice)},{'scree','pcadiag','3ddiag','robdist','qqmcd','dd','ellipse','simca','da'})
error('That kind of plot is not available for this method.')
end
case 'MCDREG'
exitno=3;
if ismember({char(choice)},{'scree','pcadiag','3ddiag','robdist','qqmcd','dd','ellipse',...
'resfit','resindex','qqlts','diag','scatter','da','simca'})
error('That kind of plot is not available for this method.')
end
case 'MLR'
exitno=3;
if ismember({char(choice)},{'scree','pcadiag','3ddiag','robdist','qqmcd','dd','ellipse',...
'resfit','resindex','qqlts','diag','scatter','da','simca'})
error('That kind of plot is not available for this method.')
end
case 'LTS'
exitno=7;
if ismember({char(choice)},{'scree','pcadiag','3ddiag',...
'robdist','qqmcd','dd','ellipse','da','simca'})
error('That kind of plot is not available for this method.')
end
if ~isfield(out,'rd')
error('Please rerun the LTS-regression again with the option plots equal to 1.')
end
case {'RAPCA','ROBPCA'}
exitno=4;
if ismember({char(choice)},{'regdiag','3ddiag','robdist','qqmcd','dd','ellipse','resfit',...
'resindex','qqlts','diag','scatter','da','simca'})
error('That kind of plot is not available for this method.')
end
case 'RPCR'
exitno=6;
if ismember({char(choice)},{'robdist','qqmcd','dd','ellipse','resfit','resindex','qqlts','diag','scatter',...
'da','simca'})
error('That kind of plot is not available for this method.')
end
case {'RSIMPLS','CSIMPLS'}
exitno=5;
if ismember({char(choice)},{'scree','robdist','qqmcd','dd','ellipse','resfit','resindex','qqlts','diag','scatter',...
'da','simca'})
error('That kind of plot is not available for this method.')
end
case 'MCDCOV'
if ismember({char(choice)},{'scree','pcadiag','regdiag','3ddiag','resfit','resindex','qqlts','diag','scatter',...
'da','simca'})
error('That kind of plot is not available for this method.')
end
exitno=6;
case {'RDA','CDA'}
exitno=3;
if ismember({char(choice)},{'scree','pcadiag','3ddiag','robdist','qqmcd','dd','ellipse',...
'resfit','resindex','qqlts','diag','scatter','regdiag','simca'})
error('That kind of plot is not available for this method.')
end
if size(out.center,2)>2
disp('Warning: Tolerance ellipses are only drawn for two-dimensional data sets.')
return
end
case {'CSIMCA','RSIMCA'}
exitno=3;
if ismember({char(choice)},{'scree','pcadiag','3ddiag','robdist','qqmcd','dd','ellipse',...
'resfit','resindex','qqlts','diag','scatter','regdiag','da'})
error('That kind of plot is not available for this method.')
end
if size(out.pca{1}.P,1) > 3
disp('Warning: The dimension of the dataset is larger than 3.')
return
end
case {'AGNES','DIANA'}
exitno=4;
if ismember({char(choice)},{'scree','pcadiag','3ddiag','robdist','qqmcd','dd','ellipse',...
'resfit','resindex','qqlts','diag','scatter','regdiag','da','silhouet','clus'})
error('That kind of plot is not available for this method.')
end
case {'MONA'}
exitno=3;
if ismember({char(choice)},{'scree','pcadiag','3ddiag','robdist','qqmcd','dd','ellipse',...
'resfit','resindex','qqlts','diag','scatter','regdiag','da','silhouet','clus','tree'})
error('That kind of plot is not available for this method.')
end
case {'PAM','FANNY'}
exitno=4;
if ismember({char(choice)},{'scree','pcadiag','3ddiag','robdist','qqmcd','dd','ellipse',...
'resfit','resindex','qqlts','diag','scatter','regdiag','da','tree','banner'})
error('That kind of plot is not available for this method.')
end
case {'CLARA'}
exitno=3;
if ismember({char(choice)},{'scree','pcadiag','3ddiag','robdist','qqmcd','dd','ellipse',...
'resfit','resindex','qqlts','diag','scatter','regdiag','da','tree','silhouet','banner'})
error('That kind of plot is not available for this method.')
end
end
if exitno==0
error(['Your attribute identifier must be one of the following names:',...
'CPCA, RAPCA, ROBPCA, CPCR, RPCR, LS, LTS, MCDREG, RSIMPLS, CSIMPLS, MCDCOV,',...
'CDA, RDA, CSIMCA, RSIMCA, AGNES, DIANA, MONA, PAM, CLARA, FANNY '])
end
%plotting what is asked for
if ask==0
whichplot(out,choice,attrib,exitno,labsd,labod,labresd,labmcd,lablts,labclus,classic,classicplots)
else
%make menu of plots
while (choice~=exitno)
switch attrib
case {'CPCA','ROBPCA','RAPCA'}
choice=menuscore(out,attrib,exitno,labsd,labod,classic,classicplots);
case {'MCDREG','MLR'}
choice=menureg(out,attrib,exitno,labsd,labresd,classic,classicplots);
case {'COV','MCDCOV'}
choice=menucov(out,attrib,exitno,labmcd,classic,classicplots);
case {'RSIMPLS','CSIMPLS'}
choice=menupls(out,attrib,exitno,labsd,labod,labresd,classic,classicplots);
case {'CPCR','RPCR'}
choice=menuscoreg(out,attrib,exitno,labsd,labod,labresd,classic,classicplots);
case {'LTS','LS'}
choice=menuls(out,attrib,exitno,labsd,labresd,lablts,classic,classicplots);
case{'CDA','RDA'}
choice=menuda(out,attrib,exitno,classic,classicplots);
case{'CSIMCA','RSIMCA'}
choice=menusimca(out,attrib,exitno,classic,classicplots);
case{'AGNES','DIANA'}
choice=menuclus1(out,attrib,exitno);
case 'MONA'
choice=menuclus2(out,attrib,exitno);
case{'PAM','FANNY'}
choice=menuclus3(out,attrib,exitno,labclus);
case 'CLARA'
choice=menuclus4(out,attrib,exitno,labclus);
end
end
%whitebg(gca,[1 1 1]) %to ensure the axes in the current figure are reset to their original
%default colours after drawing a bannerplot with AGNES or DIANA
end
%%%%%%%%%%%%% MAIN FUNCTION %%%%%%%%%%%%%%%
function whichplot(out,plotn,attrib,exitno,labsd,labod,labresd,labmcd,lablts,labclus,classic,classicplots)
%Initializing variables
switch attrib
case {'ROBPCA','RAPCA'}
Xdist=out.sd;
cutoffX=out.cutoff.sd;
cutoffO=out.cutoff.od;
OD=out.od;
k=out.k;
L=out.L;
%classical output
if isstruct(classic)
Lcl=classic.L;
Xdistcl=classic.sd;
ODcl=classic.od;
cutoffXcl=classic.cutoff.sd;
cutoffOcl=classic.cutoff.od;
attribcl='CPCA';
end
case 'MCDREG'
fitted=out.fitted;
Rdist=out.resd;
cutoffR=out.cutoff.resd;
if size(fitted,2)~=1
multi=1;
else
multi=0;
end
res=out.res;
Xdist=out.rd;
Rsquared=out.rsquared;
cutoffX=out.cutoff.rd;
Se=out.cov;
k=size(out.slope,1);
%classical output
if isstruct(classic)
attribcl=classic.class;
fittedcl=classic.fitted;
Rdistcl=classic.resd;
standrescl=classic.stdres;
cutoffRcl=classic.cutoff.resd;
rescl=classic.res;
Xdistcl=classic.md;
cutoffXcl=classic.cutoff.md;
Rsquaredcl=classic.rsquared;
Secl=classic.cov;
end
case 'MLR'
fittedcl=out.fitted;
Rdistcl=out.resd;
cutoffRcl=out.cutoff.resd;
if size(fittedcl,2)~=1
multi=1;
else
multi=0;
end
rescl=out.res;
Xdistcl=out.md;
cutoffXcl=out.cutoff.md;
Rsquaredcl=out.rsquared;
Secl=out.cov;
k=size(out.slope,1);
attribcl=out.class;
case 'RPCR'
fitted=out.fitted;
Rdist=out.resd;
cutoffR=out.cutoff.resd;
if size(fitted,2)~=1
multi=1;
else
multi=0;
end
res=out.res;
Xdist=out.sd;
Rsquared=out.rsquared;
cutoffX=out.cutoff.sd;
cutoffO=out.cutoff.od;
OD=out.od;
Se=out.cov;
k=out.k;
L=out.robpca.L;
%classical output
if isstruct(classic)
attribcl='CPCR';
Lcl=classic.cpca.L;
Xdistcl=classic.sd;
ODcl=classic.od;
cutoffOcl=classic.cutoff.od;
cutoffXcl=classic.cutoff.sd;
Rdistcl=classic.resd;
cutoffRcl=classic.cutoff.resd;
end
case 'LTS'
resid=out.res;
fitted=out.fitted;
scale=out.scale;
standres=resid/scale;
n=length(resid);
if isfield(out,'X')
x=out.X;
y=out.y;
else
x=0;
y=0;
end
Xdist=out.rd;
cutoffX=out.cutoff.rd;
cutoffY=out.cutoff.rd;
k=size(out.slope,1);
%classical output
if isstruct(classic)
attribcl='LS';
residcl=classic.res;
fittedcl=classic.fitted;
scalecl=classic.scale;
standrescl=residcl/scalecl;
Xdistcl=classic.md;
cutoffXcl=classic.cutoff.md;
ncl=length(residcl);
if isfield(classic,'X')
xcl=classic.X;
ycl=classic.y;
else
xcl=0;
ycl=0;
end
end
case 'LS'
attribcl=attrib;
residcl=out.res;
fittedcl=out.fitted;
scalecl=out.scale;
Xdistcl=out.md;
cutoffXcl=out.cutoff.md;
standrescl=out.resd;
ncl=length(residcl);
if isfield(out,'X')
xcl=out.X;
ycl=out.y;
else
xcl=0;
ycl=0;
end
k=size(out.slope,1);
case 'CPCA'
Lcl=out.L;
Xdistcl=out.sd;
ODcl=out.od;
cutoffOcl=out.cutoff.od;
cutoffXcl=out.cutoff.sd;
k=out.k;
attribcl=attrib;
case 'CPCR'
fitted=out.fitted;
Lcl=out.cpca.L;
k=out.k;
Xdistcl=out.sd;
ODcl=out.od;
cutoffOcl=out.cutoff.od;
cutoffXcl=out.cutoff.sd;
Rdistcl=out.resd;
cutoffRcl=out.cutoff.resd;
if size(fitted,2)~=1
multi=1; %multivariate analysis
else
multi=0; %univariate analysis
stdrescl=out.resd;
cutoffRcl=out.cutoff.resd;
end
attribcl=attrib;
case 'RSIMPLS'
fitted=out.fitted;
Rdist=out.resd;
cutoffR=out.cutoff.resd;
if size(fitted,2)~=1
multi=1;
else
multi=0;
end
res=out.res;
Xdist=out.sd;
cutoffX=out.cutoff.sd;
cutoffO=out.cutoff.od;
OD=out.od;
Se=out.cov;
k=out.k;
%classical output
if isstruct(classic)
attribcl='CSIMPLS';
Xdistcl=classic.sd;
ODcl=classic.od;
cutoffOcl=classic.cutoff.od;
cutoffXcl=classic.cutoff.sd;
Rdistcl=classic.resd;
cutoffRcl=classic.cutoff.resd;
end
case 'CSIMPLS'
fittedcl=out.fitted;
if size(fittedcl,2)~=1
multi=1;
else
multi=0;
end
Xdistcl=out.sd;
ODcl=out.od;
k=out.k;
cutoffXcl=out.cutoff.sd;
cutoffOcl=out.cutoff.od;
attribcl=attrib;
Rdistcl=out.resd;
cutoffRcl=out.cutoff.resd;
case 'MCDCOV'
if ~isempty(out.plane)
disp('Warning (makeplot): The MCD covariance matrix is singular. No plots can be drawn.')
return
end
covar=out.cov;
md=out.md;
rd=out.rd;
if isfield(out,'X')
data=out.X;
else
data=0;
end
center=out.center;
cutoffR=out.cutoff.rd;
cutoffM=out.cutoff.md;
if isstruct(classic)
if isfield(out,'X')
datacl=out.X;
else
datacl=0;
end
centercl=out.classic.center;
covcl=out.classic.cov;
mdcl=out.classic.md;
attribcl=out.classic.class;
end
case 'COV'
%only available inside the mcdcov function.
case 'CDA'
if isfield(out,'x')
xcl=out.x;
groupcl=out.group;
else
xcl=0;
groupcl=0;
end
methodcl=out.method;
centercl=out.center;
covcl=out.cov;
classcl=out.class;
case 'RDA'
if isfield(out,'x')
x=out.x; group=out.group;
else
x=0;group=0;
end
method=out.method;
center=out.center;
covar=out.cov;
class=out.class;
if isstruct(classic)
if isfield(out.classic,'x')
xcl=out.classic.x;
groupcl=out.classic.group;
else
xcl=0;
groupcl=0;
end
methodcl=out.classic.method;
centercl=out.classic.center;
covcl=out.classic.cov;
classcl=out.classic.class;
end
case 'RSIMCA'
if isstruct(classic)
resultcl=out.classic;
else
resultcl=0;
end
case {'DIANA', 'AGNES'}
usedvars=[];
separationstep=[];
nobs=out.number;
class=out.class ;
heights=out.heights;
objectorder= out.objectorder;
case 'MONA'
usedvars=out.usedvariable;
separationstep=out.separationstep;
nobs=out.observations;
class=out.class;
heights=[];
objectorder=out.objectorder;
case {'PAM','FANNY'}
sylinf=out.sylinf;
n=out.number;
ncluv=out.ncluv;
if size(out.x,1)==1
x=out.dys;
else
x=out.x;
end
class= out.class;
case 'CLARA'
ncluv=out.ncluv;
x=out.x;
end
%determination of the number of plots (robust or/and classic)
if strcmp(attrib,'LS') | strcmp(attrib,'CPCR') | strcmp(attrib,'CPCA') | strcmp(attrib,'MLR') | strcmp(attrib,'CDA') | strcmp(attrib,'CSIMPLS')|strcmp(attrib,'CSIMCA')
oneplot=1; %only classical plots possible
elseif (strcmp(attrib,'RAPCA') |strcmp(attrib,'MCDREG') | strcmp(attrib,'RPCR')|strcmp(attrib,'ROBPCA')| strcmp(attrib,'RSIMPLS')| strcmp(attrib,'MCDCOV')|strcmp(attrib,'LTS')|strcmp(attrib,'RDA')|strcmp(attrib,'RSIMCA')) & classicplots==0
oneplot=2; %only robust plots possible
else
oneplot=0; %both robust and classical plot in the middle of the screen
bdwidth=5;
topbdwidth=30;
set(0,'Units','pixels');
scnsize=get(0,'ScreenSize');
pos1=[bdwidth, 1/3*scnsize(4)+bdwidth, scnsize(3)/2-2*bdwidth, scnsize(4)/2-(topbdwidth+bdwidth)];
pos2=[pos1(1)+scnsize(3)/2, pos1(2), pos1(3), pos1(4)];
end
switch plotn
case 'all' %all possible plots
close
switch attrib
case {'MCDREG','MLR'}
if oneplot==0
figure('Position',pos1)
regresdiagplot(Xdist,Rdist,cutoffX,cutoffR,k,multi,attrib,labsd,labresd)
figure('Position',pos2)
regresdiagplot(Xdistcl,Rdistcl,cutoffXcl,cutoffRcl,k,multi,attribcl,labsd,labresd)
elseif oneplot==1
figure
regresdiagplot(Xdistcl,Rdistcl,cutoffXcl,cutoffRcl,k,multi,attribcl,labsd,labresd) %multi stond op 2
elseif oneplot==2
figure
regresdiagplot(Xdist,Rdist,cutoffX,cutoffR,k,multi,attrib,labsd,labresd)
end
case {'CPCA', 'ROBPCA'}
if oneplot==0
figure('Position',pos1)
screeplot(L,attrib)
figure('Position',pos2)
screeplot(Lcl,attribcl)
pos1(2)=pos1(2)-40;
pos2(2)=pos2(2)-40;
figure('Position',pos1)
scorediagplot(Xdist,OD,k,cutoffX,cutoffO,attrib,labsd,labod)
figure('Position',pos2)
scorediagplot(Xdistcl,ODcl,k,cutoffXcl,cutoffOcl,attribcl,labsd,labod)
elseif oneplot==1
figure
screeplot(Lcl,attrib)
figure
scorediagplot(Xdistcl,ODcl,k,cutoffXcl,cutoffOcl,attribcl,labsd,labod)
else
figure
screeplot(L,attrib)
figure
scorediagplot(Xdist,OD,k,cutoffX,cutoffO,attrib,labsd,labod)
end
case {'RSIMPLS','CSIMPLS'}
if oneplot==0
figure('Position',pos1)
scorediagplot(Xdist,OD,k,cutoffX,cutoffO,attrib,labsd,labod)
figure('Position',pos2)
scorediagplot(Xdistcl,ODcl,k,cutoffXcl,cutoffOcl,attribcl,labsd,labod)
pos1(2)=pos1(2)-40;
pos2(2)=pos2(2)-40;
figure('Position',pos1)
regresdiagplot(Xdist,Rdist,cutoffX,cutoffR,k,multi,attribcl,labsd,labresd)
figure('Position',pos2)
regresdiagplot(Xdistcl,Rdistcl,cutoffXcl,cutoffRcl,k,multi,attribcl,labsd,labresd)
%3D plot is still highly memory consuming 08/04/04
% if exist('OD')
% Nihil=(OD <= 1.e-06);
% OD(Nihil)=0;
% help=OD;
% elseif exist('ODcl')
% Nihil=(ODcl <= 1.e-06);
% ODcl(Nihil)=0;
% helpcl=ODcl;
% end
% pos1(2)=pos1(2)-80;
% pos2(2)=pos2(2)-80;
% if ~all(help) %in case k=rank(T)=r then OD = zero
% figure('Position',pos1)
% regresdiagplot(Xdist,Rdist,cutoffX,cutoffR,k,multi,attrib,labsd,labresd)
% figure('Position',pos2)
% regresdiagplot(Xdistcl,Rdistcl,cutoffXcl,cutoffRcl,k,multi,attribcl,labsd,labresd)
% else
% figure('Position',pos1)
% regresdiagplot3d(Xdist,OD,Rdist,cutoffX,cutoffO,cutoffR,k,attrib,multi,labsd,labod,labresd,0)
% title(['Robust 3D outlier map based on ',num2str(k),' LV'])
% figure('Position',pos2)
% regresdiagplot3d(Xdistcl,ODcl,Rdistcl,cutoffXcl,cutoffOcl,cutoffRcl,k,attribcl,multi,labsd,labod,labresd,0)
% title(['Classical 3D outlier map based on ',num2str(k),' LV'])
% end
elseif oneplot==1
figure
scorediagplot(Xdistcl,ODcl,k,cutoffXcl,cutoffOcl,attribcl,labsd,labod)
figure
regresdiagplot(Xdistcl,Rdistcl,cutoffXcl,cutoffRcl,k,multi,attribcl,labsd,labresd)
%3D plot is still highly memory consuming 08/04/04
% if exist('ODcl')
% Nihil=(ODcl <= 1.e-06);
% ODcl(Nihil)=0;
% helpcl=ODcl;
% end
% figure
% if ~all(helpcl) %in case k=rank(T)=r then OD = zero
% regresdiagplot(Rdistcl,Rdistcl,cutoffXcl,cutoffRcl,k,multi,'CPCR',labsd,labresd)
% else
% regresdiagplot3d(Xdistcl,ODcl,Rdistcl,cutoffXcl,cutoffOcl,cutoffRcl,k,attribcl,multi,labsd,labod,labresd,0)
% title(['Classical 3D outlier map based on ',num2str(k),' LV'])
% end
else
figure
scorediagplot(Xdist,OD,k,cutoffX,cutoffO,attrib,labsd,labod)
figure
regresdiagplot(Xdist,Rdist,cutoffX,cutoffR,k,multi,attrib,labsd,labresd)
%3D plot is still highly memory consuming 08/04/04
% if exist('OD')
% Nihil=(OD <= 1.e-06);
% OD(Nihil)=0;
% help=OD;
% end
% figure
% if ~all(help) %in case k=rank(T)=r then OD = zero % nog verfijnen is niet volledig nul is zeer klein (<10^-6)
% regresdiagplot(Xdist,Rdist,cutoffX,cutoffR,k,multi,attrib,labsd,labresd)
% else
% regresdiagplot3d(Xdist,OD,Rdist,cutoffX,cutoffO,cutoffR,k,attrib,multi,labsd,labod,labresd,0)
% title(['Robust 3D outlier map based on ',num2str(k),' LV'])
% end
end
case {'CPCR','RPCR'}
if oneplot==0
figure('Position',pos1)
screeplot(L,attrib)
figure('Position',pos2)
screeplot(Lcl,attrib)
pos1(2)=pos1(2)-40;
pos2(2)=pos2(2)-40;
figure('Position',pos1)
scorediagplot(Xdist,OD,k,cutoffX,cutoffO,attrib,labsd,labod)
figure('Position',pos2)
scorediagplot(Xdistcl,ODcl,k,cutoffXcl,cutoffOcl,attribcl,labsd,labod)
pos1(2)=pos1(2)-80;
pos2(2)=pos2(2)-80;
figure('Position',pos1)
regresdiagplot(Xdist,Rdist,cutoffX,cutoffR,k,multi,attribcl,labsd,labresd)
figure('Position',pos2)
regresdiagplot(Xdistcl,Rdistcl,cutoffXcl,cutoffRcl,k,multi,attribcl,labsd,labresd)
%3D plot is still highly memory consuming 08/04/04
% if exist('OD')
% Nihil=(OD <= 1.e-06);
% OD(Nihil)=0;
% help=OD;
% elseif exist('ODcl')
% Nihil=(ODcl <= 1.e-06);
% ODcl(Nihil)=0;
% helpcl=ODcl;
% end
% if ~all(help) %in case k=rank(T)=r then OD = zero
% figure('Position',pos1)
% regresdiagplot(Xdist,Rdist,cutoffX,cutoffR,k,multi,attrib,labsd,labresd)
% figure('Position',pos2)
% regresdiagplot(Xdistcl,Rdistcl,cutoffXcl,cutoffRcl,k,multi,attribcl,labsd,labresd)
% else
% figure('Position',pos1)
% regresdiagplot3d(Xdist,OD,Rdist,cutoffX,cutoffO,cutoffR,k,attrib,multi,labsd,labod,labresd,0)
% title(['Robust 3D outlier map based on ',num2str(k),' LV'])
% figure('Position',pos2)
% regresdiagplot3d(Xdistcl,ODcl,Rdistcl,cutoffXcl,cutoffOcl,cutoffRcl,k,attribcl,multi,labsd,labod,labresd,0)
% title(['Classical 3D outlier map based on ',num2str(k),' LV'])
% end
elseif oneplot==1
figure
screeplot(Lcl,attrib)
figure
scorediagplot(Xdistcl,ODcl,k,cutoffXcl,cutoffOcl,attrib,labsd,labod)
figure
regresdiagplot(Xdistcl,Rdistcl,cutoffXcl,cutoffRcl,k,multi,attribcl,labsd,labresd)
%3D plot is still highly memory consuming 08/04/04
% if exist('ODcl')
% Nihil=(ODcl <= 1.e-06);
% ODcl(Nihil)=0;
% helpcl=ODcl;
% end
% figure
% if ~all(helpcl) %in case k=rank(T)=r then OD = zero
% regresdiagplot(Xdistcl,Rdistcl,cutoffXcl,cutoffRcl,k,multi,'CPCR',labsd,labresd)
% else
% regresdiagplot3d(Xdistcl,ODcl,Rdistcl,cutoffXcl,cutoffOcl,cutoffRcl,k,attribcl,multi,labsd,labod,labresd,0)
% title(['Classical 3D outlier map based on ',num2str(k),' LV'])
% end
else
figure
screeplot(L,attrib)
figure
scorediagplot(Xdist,OD,k,cutoffX,cutoffO,attrib,labsd,labod)
figure
regresdiagplot(Xdist,Rdist,cutoffX,cutoffR,k,multi,attrib,labsd,labresd)
%3D plot is still highly memory consuming 08/04/04
% figure
% if exist('OD')
% Nihil=(OD <= 1.e-06);
% OD(Nihil)=0;
% help=OD;
% end
% if ~all(help) %in case k=rank(T)=r then OD = zero
% regresdiagplot(Xdist,Rdist,cutoffX,cutoffR,k,multi,attrib,labsd,labresd)
% else
% regresdiagplot3d(Xdist,OD,Rdist,cutoffX,cutoffO,cutoffR,k,attrib,multi,labsd,labod,labresd,0)
% title(['Robust 3D outlier map based on ',num2str(k),' LV'])
% end
end
case 'MCDCOV'
if oneplot==0
figure('Position',pos1)
distplot(rd,cutoffR,attrib,labmcd)
figure('Position',pos2)
distplot(md,cutoffM,attribcl,labmcd)
figure('Position',pos1)
chiqqplot(rd,size(data,2),attrib)
figure('Position',pos2)
chiqqplot(md,size(data,2),attribcl)
figure
ddplot(md,rd,cutoffM,attrib,labmcd)
figure
if size(data,2)~=2|data==0
axes
box on
text(0.05,0.5,'Tolerance ellipse is only available for bivariate data','color','r')
else
ellipsplot(center,covar,data,rd,labmcd)
set(findobj('color','r'),'color','m');
hold on
ellipsplot(centercl,covcl,data,md,labmcd)
set(findobj('color','r'),'color','b','linestyle',':');
hold off
legend_handles=[findobj('color','m'); findobj('color','b','linestyle',':')];
legend(legend_handles,'robust','classical','Location','best')
end
elseif oneplot==2
figure
distplot(rd,cutoffM,attrib,labmcd)
figure
chiqqplot(rd,size(data,2),attrib)
figure
ddplot(md,rd,cutoffM,attrib,labmcd)
figure
if size(data,2)~=2|data==0
axes
box on
text(0.05,0.5,'Tolerance ellipse is only available for bivariate data','color','r')
else
ellipsplot(center,covar,data,rd,labmcd,'MCDCOV')
end
end
case {'LTS','LS'}
if oneplot==0
figure('Position',pos1)
residualplot(fitted,standres,attrib,'Fitted values','Standardized LTS residual',lablts)
figure('Position',pos2)
residualplot(fittedcl,standrescl,attribcl,'Fitted value','Standardized LS residual',lablts)
pos1(2)=pos1(2)-40;
pos2(2)=pos2(2)-40;
figure('Position',pos1)
residualplot(1:n,standres,attrib,'Index','Standardized LTS residual',lablts)
figure('Position',pos2)
residualplot(1:ncl,standrescl,attribcl,'Index','Standardized LS residual',lablts)
pos1(2)=pos1(2)-80;
pos2(2)=pos2(2)-80;
figure('Position',pos1)
normqqplot(resid,attrib)
figure('Position',pos2)
normqqplot(residcl,attribcl)
pos1(2)=pos1(2)-100;
pos2(2)=pos2(2)-100;
figure('Position',pos1)
if strcmp(attrib,'LTS')
regresdiagplot(Xdist,standres,cutoffX,cutoffY,k,0,attrib,labsd,labresd);
else
regresdiagplot(Xdist,Rdist,cutoffX,cutoffR,k,1,attrib,labsd,labresd);
end
figure('Position',pos2)
if strcmp(attribcl,'LS')
regresdiagplot(Xdistcl,standrescl,cutoffXcl,0,k,0,attribcl,labsd,labresd);
else
regresdiagplot(Xdistcl,Rdistcl,cutoffXcl,cutoffRcl,k,1,attribcl,labsd,labresd);
end
pos1(2)=pos1(2)-120;
pos2(2)=pos2(2)-120;
figure('Position',pos1)
if size(x,2)~=1|x==0
axes
box on
text(0.05,0.5,'Scatter plot is only available for bivariate data','color','r')
else
lsscatter(x,y,fitted,attrib)
end
figure('Position',pos2)
if size(xcl,2)~=1|xcl==0
axes
box on
text(0.05,0.5,'Scatter plot is only available for bivariate data','color','r')
else
lsscatter(xcl,ycl,fittedcl,attribcl)
end
elseif oneplot ==1
figure
residualplot(fittedcl,standrescl,attribcl,'Fitted value','Standardized LS residual',lablts) ;
figure
residualplot(1:ncl,standrescl,attribcl,'Index','Standardized LS residual',lablts) ;
figure
normqqplot(residcl,attrib);
figure
if strcmp(attrib,'LS')
regresdiagplot(Xdistcl,standrescl,cutoffXcl,0,k,0,attrib,labsd,labresd);
else
regresdiagplot(Xdistcl,Rdistcl,cutoffXcl,cutoffRcl,k,1,attrib,labsd,labresd);
end
figure
if size(xcl,2)~=1|xcl==0
axes
box on
text(0.05,0.5,'Scatter plot is only available for bivariate data','color','r')
else
lsscatter(xcl,ycl,fittedcl,attribcl)
end
elseif oneplot==2
figure
residualplot(fitted,standres,attrib, 'Fitted value','Standardized LTS residual',lablts)
figure
residualplot(1:n,standres,attrib,'Index','Standardized LTS residual',lablts)
figure
normqqplot(resid,attrib)
figure
if strcmp(attrib,'LTS')
regresdiagplot(Xdist,standres,cutoffX,0,k,0,attrib,labsd,labresd);
else
regresdiagplot(Xdist,Rdist,cutoffX,cutoffR,k,1,attrib,labsd,labresd);
end
figure
if size(x,2)~=1|x==0
axes
box on
text(0.05,0.5,'Scatter plot is only available for bivariate data','color','r')
else
lsscatter(x,y,fitted,attrib)
end
end
case{'RDA','CDA'}
if oneplot==0
figure('Position',pos1)
daplot(x,group,center,covar,class,method)
figure('Position',pos2)
daplot(xcl,groupcl,centercl,covcl,classcl,methodcl)
elseif oneplot==1
figure
daplot(xcl,groupcl,centercl,covcl,classcl,methodcl)
elseif oneplot==2
figure
daplot(x,group,center,covar,class,method)
end
case{'RSIMCA','CSIMCA'}