收藏 分销(赏)

matlab因子旋转因子得分程序.doc

上传人:s4****5z 文档编号:8819885 上传时间:2025-03-03 格式:DOC 页数:7 大小:72KB 下载积分:10 金币
下载 相关 举报
matlab因子旋转因子得分程序.doc_第1页
第1页 / 共7页
matlab因子旋转因子得分程序.doc_第2页
第2页 / 共7页


点击查看更多>>
资源描述
因子旋转因子得分 clear all; close all; clc; % load data data = xlsread('stockdata'); % transform data xt = 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) = data(:,8).*10; xt(:,9) = data(:,9)./10; for i=1:13 zz(:,i)=(xt(:,i)-mean(xt(:,i)))/(sqrt(var(xt(:,i)))); end % correlation matrix dat = corr(zz); % Maximum Likelihood Factor Analysis without varimax rotation % factanal performs maximum-likelihood factor analysis [lambda,psi,T,stats,F] = factoran(zz,3,'xtype','data','rotate','none'); %estimated factor loadings % the estimated factor loadings matrix ld = lambda; com = diag(ld*ld'); %communalities are calculated psi = diag(dat)-diag(ld*ld'); %specific variances are calculated tbl = [lambda(:,1),lambda(:,2),lambda(:,3),com,psi] figure(1) subplot(2,2,1) s=[ 'X1 ' 'X2 ' 'X3 ' 'X5 ' 'X6 ' 'X7 ' 'X8 ' 'X9 ' 'X10' 'X11' 'X12' 'X13' 'X14']; % plot first factor against second hold on plot(lambda(:,1),lambda(:,2),'w') ylim([-0.7,0.7]) title('Factors21 - theta21') ylabel('y') xlabel('x') for i=1:13 text(lambda(i,1),lambda(i,2),s(i,1:3)); end; line([-1,1],[0,0]) line([0,0],[-1,1]) box on hold off % plot first factor against third subplot(2,2,3) hold on plot(lambda(:,1),lambda(:,3),'w') xlabel('x') ylabel('y') title('Factors31 - theta31') ylim([-0.5,0.5]) for i=1:13 text(lambda(i,1),lambda(i,3),s(i,1:3)); end; line([-1,1],[0,0]) line([0,0],[-1,1]) box on hold off % plot second factor against third subplot(2,2,2) hold on plot(lambda(:,2),lambda(:,3),'w') xlabel('x') ylabel('y') title('Factors32 - theta32') xlim([-0.7,0.7]) ylim([-0.5,0.5]) for i=1:13 text(lambda(i,2),lambda(i,3),s(i,1:3)); end; line([-1,1],[0,0]) line([0,0],[-1,1]) box on hold off % Maximum Likelihood Factor Analysis after varimax rotation lambda = rotatefactors(ld, 'Method','varimax'); %rotates the factor loadings matrix % and estimates factor loadings after varimax vl = [lambda(:,1),lambda(:,2),lambda(:,3)]; com = diag(vl*vl'); %communalities are calculated psi = diag(dat)-diag(vl*vl'); %specific variances are calculated tbl = [vl,com,psi] figure(2) subplot(2,2,1) hold on % plot first factor against second plot(lambda(:,1),lambda(:,2),'w') xlabel('x') ylabel('y') title('Factors21 - theta21') for i=1:13 text(lambda(i,1),lambda(i,2),s(i,1:3)); end; line([-1,1],[0,0]) line([0,0],[-1,1]) box on hold off % plot first factor against third subplot(2,2,3) plot(lambda(:,1),lambda(:,3),'w') xlabel('x') ylabel('y') title('Factors31 - theta31') for i=1:13 text(lambda(i,1),lambda(i,3),s(i,1:3)); end; line([-1,1],[0,0]) line([0,0],[-1,1]) box on hold off % plot second factor against third subplot(2,2,2) hold on plot(lambda(:,2),lambda(:,3),'w') xlabel('x') ylabel('y') title('Factors32 - theta32') for i=1:13 text(lambda(i,2),lambda(i,3),s(i,1:3)); end; line([-1,1],[0,0]) line([0,0],[-1,1]) box on hold off % Principal Component Method after varimax rotation % spectral decomposition [eigvec,eigval] = eigs(dat); E = ones(size(eigvec(:,1:3)))*eigval(1:3,1:3); % the estimated factor loadings matrix Q = sqrt(E).*eigvec(:,1:3); lambda = rotatefactors(Q, 'Method', 'varimax'); %rotates the factor loadings matrix %and estimates factor loadings after varimax ld = [lambda(:,1),lambda(:,2),lambda(:,3)]; com = diag(ld*ld'); %communalities are calculated psi = diag(dat)-diag(ld*ld'); %specific variances are calculated tbl = [ld,com,psi] figure(3) % plot first factor against second subplot(2,2,1) hold on plot(lambda(:,1),lambda(:,2),'w') xlabel('x') ylabel('y') title('Factors21 - theta21') for i=1:13 text(lambda(i,1),lambda(i,2),s(i,1:3)); end; line([-1,1],[0,0]) line([0,0],[-1,1]) box on hold off % plot first factor against third subplot(2,2,3) plot(lambda(:,1),lambda(:,3),'w') xlabel('x') ylabel('y') title('Factors31 - theta31') for i=1:13 text(lambda(i,1),lambda(i,3),s(i,1:3)); end; line([-1,1],[0,0]) line([0,0],[-1,1]) box on hold off % plot second factor against third subplot(2,2,2) hold on plot(lambda(:,2),lambda(:,3),'w') xlabel('x') ylabel('y') title('Factors32 - theta32') for i=1:13 text(lambda(i,2),lambda(i,3),s(i,1:3)); end; line([-1,1],[0,0]) line([0,0],[-1,1]) box on hold off % Principal Factor Method after varimax rotation % inverse of the correlation matrix dat f = inv(dat); % preliminary estimate of psi psiini = diag(diag(1./f)); psi = psiini; [eigvec,eigval] = eigs(dat-psi); EE = ones(size(eigvec(:,1:3)))*eigval(1:3,1:3); QQ = sqrt(EE).*eigvec(:,1:3); psiold = psi; psi = diag(1-sum((QQ.*QQ)')); z = psi-psiold; convergence = z; lambda = rotatefactors(QQ, 'Method', 'varimax'); %rotates the factor loadings matrix % and estimates factor loadings after varimax ld = [lambda(:,1),lambda(:,2),lambda(:,3)]; com = diag(ld*ld'); %communalities are calculated psi = diag(dat)-diag(ld*ld'); %specific variances are calculated tbl = [ld,com,psi] figure(4) % plot first factor against second subplot(2,2,1) hold on plot(lambda(:,1),lambda(:,2),'w') xlabel('x') ylabel('y') title('Factors21 - theta21') for i=1:13 text(lambda(i,1),lambda(i,2),s(i,1:3)); end; line([-1,1],[0,0]) line([0,0],[-1,1]) box on hold off % plot first factor against third subplot(2,2,3) plot(lambda(:,1),lambda(:,3),'w') xlabel('x') ylabel('y') title('Factors31 - theta31') for i=1:13 text(lambda(i,1),lambda(i,3),s(i,1:3)); end; line([-1,1],[0,0]) line([0,0],[-1,1]) box on hold off % plot second factor against third subplot(2,2,2) hold on plot(lambda(:,2),lambda(:,3),'w') xlabel('x') ylabel('y') title('Factors32 - theta32') for i=1:13 text(lambda(i,2),lambda(i,3),s(i,1:3)); end; line([-1,1],[0,0]) line([0,0],[-1,1]) box on hold off
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服