-
Notifications
You must be signed in to change notification settings - Fork 0
/
mvdemo2.m
79 lines (61 loc) · 1.96 KB
/
mvdemo2.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
clc
format compact
echo on
% Script for testing the mvartools package (PCR)
% $Id: mvdemo2.m,v 1.2 2001/12/04 09:15:01 rune Exp $
%
% MVARTOOLS, Copyright (C) 1999-2001 Rune Mathisen <[email protected]>
% MVARTOOLS comes with ABSOLUTELY NO WARRANTY; for details type
% `mvwarranty'. This is free software, and you are welcome to
% redistribute it under certain conditions; type `mvcopying' for
% details. For more information on MVARTOOLS, type 'mvreadme'.
% The acoustics data will now be loaded.
load acoustics1.mat
% It's wise to plot (and study) the raw data first ;-)
figure
subplot(2,1,1)
plot(1:length(Arun_spect),Arun_spect)
axis tight
xlabel('Raw data')
grid on
% The raw data look's noisy, lets smooth it just a little bit...!
[Arun_spect2] = mvsavgol(Arun_spect,3,2,0);
subplot(2,1,2)
plot(1:length(Arun_spect),Arun_spect)
axis tight
xlabel('Smoothed data')
grid on
% Next, we'll do a full cross-validation, calculating
% eight latent variables.
% Press any key to continue...
pause
% max number of latent variables to use in cross validation
maxlv = 5;
[press,cumpress,rmsecv,rmsec,pred] = ...
mvcrossval(Arun_spect,Arun_conc,'pcr',maxlv,'full',[],2);
% Study the RMSECV.
% Press any key to continue...
pause
% Now, we'll let a heuristic algoritm decide on how many
% latent variables to use in the finished model, and then
% calculate it.
uselv = mvoptlv(rmsecv)
% Now, lets mean center the data.
% Press any key to continue...
pause
[spect,mspect]=mvcenter(Arun_spect);
[conc,mconc]=mvcenter(Arun_conc);
[b,T,P,eigv,xres] = mvpcrsvd(spect,conc,uselv,'direct');
% We want to study the regression coefficients
% Press any key to continue...
pause
figure
plot(1:length(spect),b(uselv,:))
axis tight
grid on
% Finally, we want to plot the finished model.
% Press any key to continue...
pause
figure
mvpmplot(pred(:,uselv),Arun_conc,uselv,1,rmsecv(uselv),'RMSECV')
echo off