追記: 019/09/18
以前、psychパッケージのfa.poly functionでカテゴリカル因子分析を書いていたが、非推奨の方法だったようだ。psychパッケージの仕様書には次のように書いてある。
fa.poly
Deprecated Exploratory Factor analysis functions. Please use fa
Description
After 4 years, it is time to stop using these deprecated functions! Please see fa which includes all of the functionality of these older functions.
https://cran.r-project.org/web/packages/psych/psych.pdf
シミュレーションをしたところfaでもfa.polyで行っても同じ結果になったので、現在のところfa.polyで問題はなさそうである。将来的に改訂やfnctionの削除があるということだろうか。
fa.polyからfaへの移行を促しているのは、faに相関行列のオプションが指定できるようになったからだと思う。カテゴリカル因子分析ではテトラコリック相関やポリコリック相関などカテゴリカル変数の相関を使用する。相関行列がカテゴリカル変数の相関係数を使うことができれば、カテゴリカル因子分析ができるので、相関係数の指定ができれば別のfunctionを使う必要はないというのは確かに理にかなっていると思う。
一応、相関係数の種類についておさらいしておこう。
- ピアソンの積率相関係数: 連続変数と連続変数
- ポリコリック相関係数: 順序変数と順序変数
- ポリシリアル相関係数: 順序変数と連続変数
- テトラコリック相関係数: 2値データと2値データ
- 点双列相関係数: 2値データと連続変数
分析データに合致した相関係数の種類を選べばよい。
fa functionにはcorオプションがあり、ここで相関係数の種類を指定できる。デフォルト値は"cor"
でピアソンの積率相関係数である。"poly"
にするとポリコリック相関になる。"tet"
はテトラコリック相関である。"mixed"
はテトラコリック、ポリコリック、ピアソン、点双列相関係数、ポリシリアルが混ざる時に使用できるようだ。
"mixed"
オプションはよくわからないが、データにいくつかの尺度レベルが混じっていてもOKということなので、ちゃんと調べると面白い部分ではないだろか。
何度か書いている気がするが、2値データといっても、背後に連続変数がある、かつ正規分布が仮定ことが必要である。大阪府生まれである、東京都生まれである、といったものは因子分析に入れてはいけない。また、3年A組、B組、C組といったものも不可である。例外として、成績順にA組から順番に並んでいるのであれば、成績の代理変数として使用は可能である。
2値データであれば"tet"
、3値以上の順序尺度であれば"poly"
にするということになる。
データの呼び出しと加工
デモとして、psychパッケージに入っているIPIP-MEOのデータを2値にリコードして2×2の因子分析を実施してみる。
library("psych")
data(bfi) # IPIP-MEO のデータ
d1 <- bfi[1:25] # 因子分析に使用するのは1~25列目
library(OneR)
d2 <- bin(d1, nbins = 2, labels = c(1,2)) # データを2値に変換
library(dplyr)
d3 <- d2 %>% mutate_if(is.factor, as.integer) # 整数型への変換
str(d3) # データ構造の確認
カテゴリカル因子分析
res <- fa(d3, nfactor = 3, cor = "tet", scores=TRUE)
print(res, digit = 3)
追記以上。
Rのpsychパッケージでカテゴリカル因子分析を行った。
まずは下準備。今回もIPIP-NEOのデータを使用する。
データ・パッケージの読み込み
library("psych")
library("GPArotation")
data(bfi)
d1 <- bfi[1:25]
通常の因子分析と異なるところは、"fa"が"fa.poly"になっているところだ。
polyとはポリコリック相関係数のことである。
カテゴリカル因子分析
res01 <- fa.poly(d1, nfactor = 5)
print(res01, digit = 3)
デフォルトでは、推定法は最小残差法(ミンレス法)= “minres”であり、回転はオブリミン回転である。欠損の処理はリストワイズになっている。
デフォルト値を変更する場合には、psychパッケージのfaのところに記載がある。
https://www.rdocumentation.org/packages/psych/versions/1.8.12/topics/fa
結果
Factor Analysis using method = minres
Call: fa.poly(x = d1, nfactors = 5)
Standardized loadings (pattern matrix) based upon correlation matrix
MR2 MR1 MR3 MR5 MR4 h2 u2 com
A1 0.215 0.173 0.068 -0.474 -0.060 0.244 0.756 1.79
A2 -0.026 0.010 0.090 0.687 0.027 0.524 0.476 1.04
A3 -0.028 0.147 0.030 0.687 0.047 0.591 0.409 1.11
A4 -0.046 0.082 0.225 0.457 -0.171 0.330 0.670 1.88
A5 -0.115 0.262 0.015 0.557 0.047 0.526 0.474 1.54
C1 0.060 -0.038 0.580 -0.020 0.168 0.381 0.619 1.20
C2 0.168 -0.080 0.702 0.074 0.048 0.501 0.499 1.18
C3 0.041 -0.073 0.601 0.103 -0.074 0.357 0.643 1.13
C4 0.187 0.008 -0.659 0.022 -0.045 0.520 0.480 1.17
C5 0.202 -0.137 -0.589 0.014 0.099 0.479 0.521 1.42
E1 -0.061 -0.592 0.116 -0.098 -0.093 0.387 0.613 1.21
E2 0.108 -0.713 -0.017 -0.055 -0.057 0.605 0.395 1.07
E3 0.085 0.447 0.003 0.257 0.301 0.490 0.510 2.52
E4 0.009 0.634 0.024 0.293 -0.082 0.594 0.406 1.45
E5 0.165 0.453 0.301 0.037 0.218 0.461 0.539 2.59
N1 0.846 0.107 0.008 -0.127 -0.050 0.708 0.292 1.09
N2 0.808 0.047 0.013 -0.098 0.018 0.649 0.351 1.04
N3 0.740 -0.090 -0.042 0.074 0.022 0.594 0.406 1.06
N4 0.505 -0.390 -0.138 0.093 0.090 0.532 0.468 2.21
N5 0.521 -0.215 -0.013 0.231 -0.172 0.403 0.597 2.02
O1 0.014 0.122 0.081 0.018 0.559 0.382 0.618 1.14
O2 0.206 0.044 -0.092 0.165 -0.489 0.295 0.705 1.70
O3 0.026 0.179 0.016 0.078 0.648 0.525 0.475 1.19
O4 0.150 -0.355 -0.037 0.203 0.447 0.353 0.647 2.63
O5 0.133 0.102 -0.042 0.038 -0.597 0.367 0.633 1.18
MR2 MR1 MR3 MR5 MR4
SS loadings 2.828 2.492 2.328 2.254 1.898
Proportion Var 0.113 0.100 0.093 0.090 0.076
Cumulative Var 0.113 0.213 0.306 0.396 0.472
Proportion Explained 0.240 0.211 0.197 0.191 0.161
Cumulative Proportion 0.240 0.451 0.648 0.839 1.000
With factor correlations of
MR2 MR1 MR3 MR5 MR4
MR2 1.000 -0.209 -0.187 -0.047 0.001
MR1 -0.209 1.000 0.238 0.317 0.145
MR3 -0.187 0.238 1.000 0.214 0.205
MR5 -0.047 0.317 0.214 1.000 0.201
MR4 0.001 0.145 0.205 0.201 1.000
Mean item complexity = 1.5
Test of the hypothesis that 5 factors are sufficient.
The degrees of freedom for the null model are 300 and the objective function was 9.285 with Chi Square of 25902.42
The degrees of freedom for the model are 185 and the objective function was 0.931
The root mean square of the residuals (RMSR) is 0.031
The df corrected root mean square of the residuals is 0.04
The harmonic number of observations is 2800 with the empirical chi square 1643.362 with prob < 6.06e-232
The total number of observations was 2800 with Likelihood Chi Square = 2593.892 with prob < 0
Tucker Lewis Index of factoring reliability = 0.8472
RMSEA index = 0.0684 and the 90 % confidence intervals are 0.0659 0.0705
BIC = 1125.478
Fit based upon off diagonal values = 0.982
Measures of factor score adequacy
MR2 MR1 MR3 MR5 MR4
Correlation of (regression) scores with factors 0.937 0.909 0.898 0.898 0.872
Multiple R square of scores with factors 0.877 0.827 0.806 0.807 0.761
Minimum correlation of possible factor scores 0.755 0.654 0.612 0.614 0.522