全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1803 1
2009-11-05
IML里面最后作出的P和PROC 出来的tb1中的主成分不一样。估计是P的公式有问题,但是实在没有找出来。
高手给我看看这是为什么?多谢!下面是code:
%let n=5;
proc iml;
reset deflib=work;
a={22  10   2   3   7,
      14   7  10   0   8,
      -1  13  -1 -11   3,
      -3  -2  13  -2   4,
       9   8   1  -2   4,
       9   1  -7   5  -1,
       2  -6   6   5   1,
       4   5   0  -2   2};
create tb from a;
append from a ;
call svd(u,q,v,a);
reset fuzz;
print a u q v ;
sq=sum(q);
print sq;
dq=diag(q);
print dq;
trace=trace(dq);
print trace;
retain_eig={0};
idx={0};
do i=1 to &n.;
eig=q[i];
retain_eig=retain_eig+eig;
rate_eig=retain_eig/sq;
if rate_eig >= 0.7 then do;idx=i; new_eig=q[1:idx];stop;end;
end;
print retain_eig;
print idx;
print new_eig;
u1=u[1:idx,];
print u1;
p=a*(u1)`;
print p;

quit;

proc princomp data=tb out=tb1;
run;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2009-11-8 02:26:01
I am not sure where your problem is. But here is the one having both rerults are matched. The eigenvalue calculations are based on correlation matrix.

proc iml;
a={22  10   2   3   7,
      14   7  10   0   8,
      -1  13  -1 -11   3,
      -3  -2  13  -2   4,
       9   8   1  -2   4,
       9   1  -7   5  -1,
       2  -6   6   5   1,
       4   5   0  -2   2};
create tb from a;
append from a ;

       n=nrow(a);

                 aa_corr=corr(a);
         eig=eigval(aa_corr);

        print eig  aa_corr ;

quit;

proc princomp data=tb;
run;


proc iml;
  n=800;
  seed=4598763;
  et=repeat(0,3,n);
  mu={0 0 0};
  sigma={1 0.7 0.3,
             0.7 1 0.5,
                      0.3 0.5 1}
                 ;

   CALL VNORMAL( a, mu, sigma, n ,seed );
   create tb from a;
   append from a;

          n=nrow(a);

                 aa_corr=corr(a);
         eig=eigval(aa_corr);

        print eig  aa_corr ;


quit;

proc princomp data=tb;
run;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群