📄 mddemo.m
字号:
echo on, clc
%MDDEMO Demonstrates MDPCA for PCA with missing data
% This script demos the mdpca function. It takes the pca data
% from the PLS_Toolbox and leaves out 1% of the data at random.
% Results can be compared to using pca on the orignal data
% with nothing left out.
% The pcadata will be loaded and mean centered.
pause
echo off
% Copyright
% Barry M. Wise
% 1992
% Modified May 1994
rand('uniform')
load pcadata
mpart1 = mncn(part1/10);
[m,n] = size(mpart1);
echo on
% Now we can use the pca function to do pca the usual
% way on the original data. The scores and loading will be
% calculated but the plots will be supressed.
pause
[oscores,oloads,ssq,res,q,tsq] = pca(mpart1,0,1:m,4);
pause
% Now 1% of the data will be left out at random
% and replaced with the flag 9999.
echo off
x = rand(m,n);
missing = [];
for i = 1:m
for j = 1:n
if x(i,j) > .99
mpart1(i,j) = 9999;
missing = [missing; [i j]];
end
end
end
pause
echo on
% We'll now use the mdpca function on the data. The function
% will iterate until the estimated values of the missing data
% converge. We'll use a tolerance of .001 rather than the
% default of .00001.
pause
[scores,loads,estdata] = mdpca(mpart1,4,9999,.001);
pause
% We can compare the scores and loadings by plotting them on top
% of each other.
pause
echo off
plot(scores,'+'), hold on, plot(oscores,'-'), hold off
title('Original scores (solid) and estimated scores (+)')
xlabel('Sample Number')
ylabel('Score')
pause
echo on
% Note some scores might be negative of originals. We can also
% compare the loadings vectors.
echo off
pause
plot(loads,'-'), hold on, plot(oloads,'--'), hold off
title('Original loadings (dashed) and estimated loadings (solid)')
xlabel('Variable Number')
ylabel('Loading')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -