-
Notifications
You must be signed in to change notification settings - Fork 0
/
mvtestval.m
66 lines (55 loc) · 1.86 KB
/
mvtestval.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
function [press,cumpress,rmsep,pred] = mvtestval(X,y,b,lv,my)
%MVTESTVAL -- test-set validation of multivariate model
%
% Usage:
% [press,cumpress,rmsep,pred] = mvtestval(X,y,b,lv,my)
%
% Inputs:
% X scaled/preprocessed predictor variables
% y reference measurements (vector)
% b regression coefficients matrix
% maxlv max number of latent variables to use (optional)
% my mean value of y-vector (if mean centered, optional)
%
% Outputs:
% press prediction residual error sum of squares
% cumpress cumulative prediction residual error sum of squares
% rmsep root mean square error of prediction
% pred predicted values
%
% Description:
% Test-set validation of multivariate model. For more model
% statistics, use 'mvpmstats'. See also the validation functions:
% 'mvcvbyclass' and 'mvtestval'.
%
% Copying:
% 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'.
% $Id: mvtestval.m,v 1.2 2001/12/04 10:16:12 rune Exp $
[rb,cb] = size(b);
[rx,cx] = size(X);
if nargin < 5,
my = 0;
end
% if no value is given for lv, calculate for all factors in b
if (nargin < 4) | (isempty(b) == 1),
lv = rb;
end
% initializing variables
pred = zeros(rx,lv);
press = zeros(rx,lv);
for f = 1:lv,
% predicting values
pred(:,f) = mvpredict(X,b,f);
% rescaling
pred(:,f) = mvrecenter(pred(:,f),my);
% prediction error
press(:,f) = (pred(:,f) - y).^2;
end
% statistics
cumpress = sum(press,1);
rmsep = sqrt(cumpress/rx);
%end of mvtestval