資源描述:
《matlab因子旋轉(zhuǎn)因子得分程序》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、因子旋轉(zhuǎn)因子得分clearall;closeall;clc;%loaddatadata=xlsread('stockdata');%transformdataxt=data;xt(:,[1,3,10,11])=data(:,[1,3,10,11])./(10.^9);xt(:,[2,4])=data(:,[2,4])./(10.^10);xt(:,5)=data(:,5)./(10.^5);xt(:,[6,12,13])=data(:,[6,12,13])./(10.^11);xt(:,7)=data(:,7)./(10.^2);xt(:,8)=d
2、ata(:,8).*10;xt(:,9)=data(:,9)./10;fori=1:13zz(:,i)=(xt(:,i)-mean(xt(:,i)))/(sqrt(var(xt(:,i))));end%correlationmatrixdat=corr(zz);%MaximumLikelihoodFactorAnalysiswithoutvarimaxrotation%factanalperformsmaximum-likelihoodfactoranalysis[lambda,psi,T,stats,F]=factoran(zz,3,'xtype
3、','data','rotate','none');%estimatedfactorloadings%theestimatedfactorloadingsmatrixld=lambda;com=diag(ld*ld');%communalitiesarecalculatedpsi=diag(dat)-diag(ld*ld');%specificvariancesarecalculatedtbl=[lambda(:,1),lambda(:,2),lambda(:,3),com,psi]figure(1)subplot(2,2,1)s=['X1''X2
4、''X3''X5''X6''X7''X8''X9''X10''X11''X12''X13''X14'];%plotfirstfactoragainstsecondholdonplot(lambda(:,1),lambda(:,2),'w')ylim([-0.7,0.7])title('Factors21-theta21')ylabel('y')xlabel('x')fori=1:13text(lambda(i,1),lambda(i,2),s(i,1:3));end;line([-1,1],[0,0])line([0,0],[-1,1])boxon
5、holdoff%plotfirstfactoragainstthirdsubplot(2,2,3)holdonplot(lambda(:,1),lambda(:,3),'w')xlabel('x')ylabel('y')title('Factors31-theta31')ylim([-0.5,0.5])fori=1:13text(lambda(i,1),lambda(i,3),s(i,1:3));end;line([-1,1],[0,0])line([0,0],[-1,1])boxonholdoff%plotsecondfactoragainstt
6、hirdsubplot(2,2,2)holdonplot(lambda(:,2),lambda(:,3),'w')xlabel('x')ylabel('y')title('Factors32-theta32')xlim([-0.7,0.7])ylim([-0.5,0.5])fori=1:13text(lambda(i,2),lambda(i,3),s(i,1:3));end;line([-1,1],[0,0])line([0,0],[-1,1])boxonholdoff%MaximumLikelihoodFactorAnalysisaftervar
7、imaxrotationlambda=rotatefactors(ld,'Method','varimax');%rotatesthefactorloadingsmatrix%andestimatesfactorloadingsaftervarimaxvl=[lambda(:,1),lambda(:,2),lambda(:,3)];com=diag(vl*vl');%communalitiesarecalculatedpsi=diag(dat)-diag(vl*vl');%specificvariancesarecalculatedtbl=[vl,
8、com,psi]figure(2)subplot(2,2,1)holdon%plotfirstfactoragainsts