因子負荷量による並べ替え Last modified: Apr 13, 2009
目的
因子負荷量をソートして表示する。
print.loadings の sort=TRUE は,期待される結果を返さないので。
使用法
sort.loadings(x)
引数
x factanal 関数が返すオブジェクト
ソース
インストールは,以下の 1 行をコピーし,R コンソールにペーストする
source("http://aoki2.si.gunma-u.ac.jp/R/src/sort.loadings.R", encoding="euc-jp")
# 因子負荷量の大きさの順に変数を並べ替える
sort.loadings <- function(x) # factanalが返すオブジェクト
{
a <- x$loadings
y <- abs(a) # 因子負荷量の絶対値
z <- apply(y, 1, which.max) # 各変数をどの因子に含めるべきか
loadings <- NULL # 結果
for (i in 1:ncol(y)) {
b <- a[z == i,, drop=FALSE]
if (nrow(b)) {
t <- order(b[, i, drop=FALSE], decreasing=TRUE) # 因子単位で並べ替え情報を得る
loadings <- rbind(loadings, b[t,, drop=FALSE])
}
}
class(loadings) <- "loadings" # クラスの設定
return(loadings) # 結果を返す
}
使用例
set.seed(123)
library(MASS)
x <- mvrnorm(n=Harman74.cor$n.obs, mu=Harman74.cor$center, Sigma=Harman74.cor$cov)
ans <- factanal(x, factors=5, rotation="promax")
sort.loadings(ans)
結果の出力例
> set.seed(123)
> library(MASS)
> x <- mvrnorm(n=Harman74.cor$n.obs, mu=Harman74.cor$center, Sigma=Harman74.cor$cov)
> ans <- factanal(x, factors=5, rotation="promax")
> sort.loadings(ans)
Loadings:
Factor1 Factor2 Factor3 Factor4 Factor5
Deduction 0.682 0.308 -0.253 -0.113
ProblemReasoning 0.657 -0.143 0.122 0.201 -0.124
VisualPerception 0.644 -0.147 0.219
NumberFigure 0.614 -0.255 0.291 -0.112
NumericalPuzzles 0.589 -0.115 0.296
PaperFormBoard 0.579 -0.453 0.124 0.263
Flags 0.564 0.147 -0.329
SeriesCompletion 0.530 0.200
Cubes 0.516
FigureRecognition 0.294 -0.109 0.262
SentenceCompletion 0.982 -0.154
PargraphComprehension 0.837
WordMeaning 0.110 0.665 0.137 -0.126
GeneralInformation 0.138 0.570
WordClassification 0.139 0.561 0.171
Addition 0.867
CountingDots 0.727 0.282
ArithmeticProblems 0.307 0.112 0.423 -0.138
Code -0.156 0.242 0.715 0.225
FigureWord 0.167 -0.154 -0.193 0.709
ObjectNumber 0.176 0.550 -0.106
WordRecognition -0.129 0.176 0.323
NumberRecognition 0.246
StraightCurvedCapitals 0.125 0.235 0.804
Factor1 Factor2 Factor3 Factor4 Factor5
SS loadings 3.573 3.144 1.993 1.958 1.032
Proportion Var 0.149 0.131 0.083 0.082 0.043
Cumulative Var 0.149 0.280 0.363 0.444 0.487
print 関数で sort=TRUE を指定したときの出力は,以下のようにしかならない
> print(ans$loadings, sort=TRUE)
Loadings:
Factor1 Factor2 Factor3 Factor4 Factor5
VisualPerception 0.644 -0.147 0.219
Cubes 0.516
PaperFormBoard 0.579 -0.453 0.124 0.263
Flags 0.564 0.147 -0.329
NumberFigure 0.614 -0.255 0.291 -0.112
Deduction 0.682 0.308 -0.253 -0.113
NumericalPuzzles 0.589 -0.115 0.296
ProblemReasoning 0.657 -0.143 0.122 0.201 -0.124
SeriesCompletion 0.530 0.200
GeneralInformation 0.138 0.570
PargraphComprehension 0.837
SentenceCompletion 0.982 -0.154
WordClassification 0.139 0.561 0.171
WordMeaning 0.110 0.665 0.137 -0.126
Addition 0.867
CountingDots 0.727 0.282
Code -0.156 0.242 0.715 0.225
ObjectNumber 0.176 0.550 -0.106
FigureWord 0.167 -0.154 -0.193 0.709
StraightCurvedCapitals 0.125 0.235 0.804
WordRecognition -0.129 0.176 0.323
NumberRecognition 0.246
FigureRecognition 0.294 -0.109 0.262
ArithmeticProblems 0.307 0.112 0.423 -0.138
Factor1 Factor2 Factor3 Factor4 Factor5
SS loadings 3.573 3.144 1.993 1.958 1.032
Proportion Var 0.149 0.131 0.083 0.082 0.043
Cumulative Var 0.149 0.280 0.363 0.444 0.487
直前のページへ戻る
E-mail to Shigenobu AOKI