プロマックス解の因子間相関係数行列 Last modified: Oct 02, 2008
目的
プロマックス解の因子間相関係数行列を求める。
使用法
factor.correlation(x, factors, ...)
引数
x データ行列またはデータ・フレーム
factors 抽出する因子数
... 下位の関数に引き渡すそれ以外の引数
ソース
インストールは,以下の 1 行をコピーし,R コンソールにペーストする
source("http://aoki2.si.gunma-u.ac.jp/R/src/factor.correlation.R", encoding="euc-jp")
# プロマックス解の因子間相関係数行列
factor.correlation <- function(x, factors, ...)
{
ans <- factanal(x, factors, rotation="none", ...) # 回転を行わない結果を求める
ans2 <- promax(ans$loadings) # プロマックス回転による結果を求める
name <- colnames(ans2$loadings) # 名前の保存
o <- order(colSums(ans2$loadings^2), decreasing=TRUE) # SS loadings の大きい順
ans2$loadings <- ans2$loadings[, o] # loadings の並べ替え(行)
colnames(ans2$loadings) <- name # 名前の付け替え
class(ans2$loadings) <- "loadings" # class がなくなるので再設定
ans2$rotmat <- ans2$rotmat[o, o] # rotmat の並べ替え(行・列)
ans3 <- ans2$rotmat # 回転行列を取り出す
r <- solve(t(ans3) %*% ans3) # 因子間相関係数行列を計算する
colnames(r) <- rownames(r) <- name # 名前を付ける(必須ではない)
return(list(loadings=ans2$loadings, r=r)) # プロマックス解と因子間相関係数行列
}
使用例
> dat <- read.table("pfa.data", header=TRUE) # ファイルからデータを読んだ
> dat
var1 var2 var3 var4 var5 var6 var7 var8 var9 var10
1 935 955 926 585 1010 925 1028 807 769 767
2 817 905 901 632 1004 950 957 844 781 738
3 768 825 859 662 893 900 981 759 868 732
4 869 915 856 448 867 874 884 802 804 857
5 787 878 880 592 871 874 884 781 782 807
6 738 848 850 569 814 950 957 700 870 764
7 763 862 839 658 887 900 1005 604 709 753
8 795 890 841 670 853 874 859 701 680 772
9 903 877 919 460 818 849 884 700 718 716
10 761 765 881 485 846 900 981 728 781 714
11 747 792 800 564 796 849 932 682 746 767
12 771 802 840 609 824 874 859 668 704 710
13 785 878 805 527 911 680 884 728 709 747
14 657 773 820 612 810 849 909 698 746 771
15 696 785 791 578 774 725 932 765 706 795
16 724 785 870 509 746 849 807 763 724 760
17 712 829 838 516 875 725 807 754 762 585
18 756 863 815 474 873 725 957 624 655 620
19 622 759 786 619 820 769 807 673 698 695
20 668 753 751 551 834 849 807 601 655 642
> factor.correlation(dat, 3)
$loadings
Loadings:
Factor1 Factor2 Factor3
var1 0.714 0.494
var2 0.859 0.183
var3 0.362 0.496 0.233
var4 0.227 -0.559
var5 1.064 -0.128 -0.421
var6 0.719
var7 0.373 0.339 -0.150
var8 0.212 0.539
var9 -0.179 0.944 -0.252
var10 -0.215 0.591 0.240
Factor1 Factor2 Factor3
SS loadings 2.775 2.483 0.978
Proportion Var 0.277 0.248 0.098
Cumulative Var 0.277 0.526 0.624
$r
Factor1 Factor2 Factor3
Factor1 1.0000000 0.5589351 0.2335774
Factor2 0.5589351 1.0000000 0.2870210
Factor3 0.2335774 0.2870210 1.0000000
直前のページへ戻る
E-mail to Shigenobu AOKI