📄 pcapro.m
字号:
function [scores,res,tsqvals] = pcapro(newdata,loads,ssq,q,tsq,plots,mo)
%PCAPRO Projects new data on old principal components model
% The input variables are the new data (newdata), the old
% loadings (loads), the old variance info (ssq), the limit
% for q (q), the limit for t^2 (tsq) and an optional variable
% (plots) which suppresses the plots when set to 0. The outputs
% are the new scores (scores), residuals (res) and t^2 values
% (tsqvals). All of these are plotted as the function proceeds
% if plots ~= 0. The I/O format is:
% [scores,resids,tsqs] = pcapro(newdata,loads,ssq,q,tsq,plots);
%
% Warning: Be sure to use the same scaling as original data!
% Copyright
% Barry M. Wise
% 1991, 1992
% Modified by B.M. Wise, November 1993
[m,n] = size(loads);
[ms,ns] = size(newdata);
[mss,nss] = size(ssq);
if nargin < 6
plots = 1;
end
if ns ~= m
error('Number of variables in new data not consistent with loadings')
end
scores = newdata*loads;
scl = 1:ms;
scllim = [1 ms];
temp = [1 1];
if plots ~= 0
for i = 1:n
if nargin == 7
pclim = temp*sqrt(ssq(i,2))*ttestp(.025,mo-i,2);
else
pclim = temp*sqrt(ssq(i,2))*1.96;
end
plot(scl,scores(:,i),scllim,pclim,'--b',scllim,-pclim,'--b')
hold on, plot(scl,scores(:,i),'+g'), hold off
xlabel('Sample Number')
str = sprintf('Score on PC# %g',i);
ylabel(str)
title('New Sample Scores with 95% Limits from Old Model')
pause
end
end
if ms > m
I = eye(m);
resmat = ((I - loads*loads')*newdata');
else
resmat = newdata' - loads*scores';
end
res = (sum(resmat.^2))';
lim = [q q];
if plots ~= 0
plot(scl,res,scl,res,'+g',scllim,lim,'--b')
title('New Sample Residuals with Limits from Old Model')
xlabel('Sample Number')
ylabel('Residual')
pause
end
tsqvals = sum((scores.^2*inv(diag(ssq(1:n,2))))');
if plots ~= 0
if n == 1
disp('T^2 not displayed when number of PCs = 1')
else
tlim = [tsq tsq];
plot(scl,tsqvals,scl,tsqvals,'+g',scllim,tlim,'--b')
title('New Samples Value of T^2 with 95% Limit From Old Model')
xlabel('Sample Number')
ylabel('Value of T^2')
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -