井出草平の研究ノート

RのpoLCAパッケージで潜在クラス分析を行う

Rので潜在クラス分析を行う。

Rで潜在クラス分析ができるパッケージは3つある。

他にMclustというパッケージがあるが、つまり潜在プロファイル分析(連続変数)のパッケージで潜在クラス分析には使えない。

ここではpoLCAパッケージを使用する。

データセットgss82を使用する。このデータはpoLCAパッケージに含まれるのでインストールをする必要がある。ちなみに、潜在クラス分析の古典的な解説書であるMcCutcheon(1987: 30)の図3.1で使用されている例である。

gss82の変数は4つである。カッコ内は変数の値である。

  • PURPOSE; 調査の目的について意見(good/depends/waste of time and money )
  • ACCURACY ; 調査の正確性(mostly true/not true)
  • UNDERSTA; 調査の質問を理解していたか (good/fair, poor)
  • COOPERAT; 面接調査に協力的だったか (interested/cooperative/impatient, hostile )

2クラスモデルを走らせてみる。

data(gss82) #データセットをgss82に設定
f <- cbind(PURPOSE,ACCURACY,UNDERSTA,COOPERAT)~1 #fomulaの設定。潜在クラス分析に入れる変数を選ぶ
gss.lc2 <- poLCA(f,gss82,nclass=2,maxiter=3000,nrep=100) #2クラスモデル

maxiterは反復回数である。デフォルトは1000である。収束しない場合にはmaxiterを多少多めにしておいてもよい。nrepはモデル推定をする回数。デフォルトは1である。初期値はprobs.startで与える。

結果は次のようになる

$PURPOSE
            Good Depends Waste of time
class 1:  0.8953  0.0579        0.0468
class 2:  0.2154  0.2066        0.5780

$ACCURACY
          Mostly true Not true
class 1:       0.6367   0.3633
class 2:       0.0297   0.9703

$UNDERSTA
            Good Fair/Poor
class 1:  0.8327    0.1673
class 2:  0.7422    0.2578

$COOPERAT
          Interested Cooperative Impatient
class 1:      0.8840      0.1043    0.0117
class 2:      0.6478      0.2498    0.1024

Estimated class population shares 
 0.8077 0.1923 
 
Predicted class memberships (by modal posterior prob.) 
 0.8136 0.1864 

統計量やフィッティングの指標は以下のように出力される。

AIC(2): 5592.536
BIC(2): 5658.729
G^2(2): 79.33723 (Likelihood ratio/deviance statistic) 
X^2(2): 93.25329 (Chi-square goodness of fit) 

poLCAでBICは出力できるが、BLRT(Bootstrap Likelihood Ratio Test)を出力することはできないようだ。

Latent Class Analysis (Quantitative Applications in the Social Sciences)

Latent Class Analysis (Quantitative Applications in the Social Sciences)