matlab factoran函数,Factor analysis

Create some pseudorandom raw data.

rng default % For reproducibility

n = 100;

X1 = 5 + 3*rand(n,1); % Factor 1

X2 = 20 - 5*rand(n,1); % Factor 2

Create six data vectors from the raw data, and add random noise.

Y1 = 2*X1 + 3*X2 + randn(n,1);

Y2 = 4*X1 + X2 + 2*randn(n,1);

Y3 = X1 - X2 + 3*randn(n,1);

Y4 = -2*X1 + 4*X2 + 4*randn(n,1);

Y5 = 3*(X1 + X2) + 5*randn(n,1);

Y6 = X1 - X2/2 + 6*randn(n,1);

Create a data matrix from the data vectors.

X = [Y1,Y2,Y3,Y4,Y5,Y6];

Extract the two factors from the noisy data matrix X using factoran. Display the outputs.

m = 2;

[lambda,psi,T,stats,F] = factoran(X,m);

disp(lambda)

0.8666 0.4828

0.8688 -0.0998

-0.0131 -0.5412

0.2150 0.8458

0.7040 0.2678

-0.0806 -0.2883

disp(psi)

0.0159

0.2352

0.7070

0.2385

0.4327

0.9104

disp(T)

0.8728 0.4880

0.4880 -0.8728

disp(stats)

loglike: -0.0531

dfe: 4

chisq: 5.0335

p: 0.2839

disp(F(1:10,:))

1.8845 -0.6568

-0.1714 -0.8113

-1.0534 2.0743

1.0390 -1.1784

0.4309 0.9907

-1.1823 0.6570

-0.2129 1.1898

-0.0844 -0.7421

0.5854 -1.1379

0.8279 -1.9624

View the correlation matrix of the data.

corrX = corr(X)

corrX = 6×6

1.0000 0.7047 -0.2710 0.5947 0.7391 -0.2126

0.7047 1.0000 0.0203 0.1032 0.5876 0.0289

-0.2710 0.0203 1.0000 -0.4793 -0.1495 0.1450

0.5947 0.1032 -0.4793 1.0000 0.3752 -0.2134

0.7391 0.5876 -0.1495 0.3752 1.0000 -0.2030

-0.2126 0.0289 0.1450 -0.2134 -0.2030 1.0000

Compare corrX to its corresponding values returned by factoran, lambda*lambda' + diag(psi).

C0 = lambda*lambda' + diag(psi)

C0 = 6×6

1.0000 0.7047 -0.2726 0.5946 0.7394 -0.2091

0.7047 1.0000 0.0426 0.1023 0.5849 -0.0413

-0.2726 0.0426 1.0000 -0.4605 -0.1542 0.1571

0.5946 0.1023 -0.4605 1.0000 0.3779 -0.2611

0.7394 0.5849 -0.1542 0.3779 1.0000 -0.1340

-0.2091 -0.0413 0.1571 -0.2611 -0.1340 1.0000

factoran obtains lambda and psi that correspond closely to the correlation matrix of the original data.

View the results without using rotation.

[lambda,psi,T,stats,F] = factoran(X,m,'Rotate','none');

disp(lambda)

0.9920 0.0015

0.7096 0.5111

-0.2755 0.4659

0.6004 -0.6333

0.7452 0.1098

-0.2111 0.2123

disp(psi)

0.0159

0.2352

0.7070

0.2385

0.4327

0.9104

disp(T)

1 0

0 1

disp(stats)

loglike: -0.0531

dfe: 4

chisq: 5.0335

p: 0.2839

disp(F(1:10,:))

1.3243 1.4929

-0.5456 0.6245

0.0928 -2.3246

0.3318 1.5356

0.8596 -0.6544

-0.7114 -1.1504

0.3947 -1.1424

-0.4358 0.6065

-0.0444 1.2789

-0.2350 2.1169

Compute the factors using only the covariance matrix of X.

X2 = cov(X);

[lambda2,psi2,T2,stats2] = factoran(X2,m,'Xtype','covariance','Nobs',n)

lambda2 = 6×2

0.8666 0.4828

0.8688 -0.0998

-0.0131 -0.5412

0.2150 0.8458

0.7040 0.2678

-0.0806 -0.2883

psi2 = 6×1

0.0159

0.2352

0.7070

0.2385

0.4327

0.9104

T2 = 2×2

0.8728 0.4880

0.4880 -0.8728

stats2 = struct with fields:

loglike: -0.0531

dfe: 4

chisq: 5.0335

p: 0.2839

The results are the same as with the raw data, except factoran cannot compute the factor scores matrix F for covariance data.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值