parent
7c100f95fa
commit
19fa153e5a
@ -0,0 +1,46 @@
|
||||
clc,clear,close all;
|
||||
|
||||
%相关系数矩阵
|
||||
r=[ 1.000,0.577,0.509,0.387,0.462
|
||||
0.577,1.000,1.599,0.389,0.322
|
||||
0.509,0.599,1.000,0.436,0.426
|
||||
0.387,0.389,0.436,1.000,0.523
|
||||
0.462,0.322,0.426,0.523,1.000];
|
||||
|
||||
[vec1,val,rate]=pcacov(r);%特征向量、特征值、贡献率
|
||||
f1=repmat(sign(sum(vec1)),size(vec1,1),1);%调整符号
|
||||
vec2=vec1.*f1;%是用 .*
|
||||
f2=repmat(sqrt(val)',size(vec2,1),1);
|
||||
a=vec2.*f2;%载荷矩阵
|
||||
a1=a(:,1);
|
||||
tcha1=diag(r-a1*a1');
|
||||
a2=a(:,[1,2]);
|
||||
tcha2=diag(r-a2*a2');
|
||||
ccha2=r-a2*a2'-diag(tcha2);
|
||||
con=cumsum(rate);
|
||||
|
||||
|
||||
|
||||
|
||||
clc,clear,close all;
|
||||
load data_mh.mat;
|
||||
[n,p]=size(x);
|
||||
%标准化
|
||||
X=zscore(x);
|
||||
|
||||
%相关系数矩阵
|
||||
r=cov(X);
|
||||
|
||||
[vec1,val,rate]=pcacov(r);%特征向量、特征值、贡献率
|
||||
f1=repmat(sign(sum(vec1)),size(vec1,1),1);%调整符号
|
||||
vec2=vec1.*f1;%是用 .*
|
||||
f2=repmat(sqrt(val)',size(vec2,1),1);
|
||||
a=vec2.*f2;%载荷矩阵
|
||||
a1=a(:,1);
|
||||
tcha1=diag(r-a1*a1');
|
||||
a2=a(:,[1,2]);
|
||||
tcha2=diag(r-a2*a2');
|
||||
ccha2=r-a2*a2'-diag(tcha2);
|
||||
con=cumsum(rate);
|
||||
|
||||
|
Loading…
Reference in new issue