library(psych)
library(moments)
library(lavaan)
## This is lavaan 0.6-11
## lavaan is FREE software! Please report any bugs.
##
## 載入套件:'lavaan'
## 下列物件被遮斷自 'package:psych':
##
## cor2cov
library(reshape2)
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.6 v purrr 0.3.4
## v tibble 3.1.6 v dplyr 1.0.9
## v tidyr 1.2.0 v stringr 1.4.0
## v readr 2.1.2 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x ggplot2::%+%() masks psych::%+%()
## x ggplot2::alpha() masks psych::alpha()
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
data(PoliticalDemocracy)
dta <- PoliticalDemocracy
str(dta)
## 'data.frame': 75 obs. of 11 variables:
## $ y1: num 2.5 1.25 7.5 8.9 10 7.5 7.5 7.5 2.5 10 ...
## $ y2: num 0 0 8.8 8.8 3.33 ...
## $ y3: num 3.33 3.33 10 10 10 ...
## $ y4: num 0 0 9.2 9.2 6.67 ...
## $ y5: num 1.25 6.25 8.75 8.91 7.5 ...
## $ y6: num 0 1.1 8.09 8.13 3.33 ...
## $ y7: num 3.73 6.67 10 10 10 ...
## $ y8: num 3.333 0.737 8.212 4.615 6.667 ...
## $ x1: num 4.44 5.38 5.96 6.29 5.86 ...
## $ x2: num 3.64 5.06 6.26 7.57 6.82 ...
## $ x3: num 2.56 3.57 5.22 6.27 4.57 ...
#感覺這11個items可以被分配成兩個factors
#factor loading 因素負載量越高越好,越能反映子構念
print.psych(fa(dta[, 1:11], nfactor = 2, fm = "pa", rotate = "promax"), cut = .3)
## Factor Analysis using method = pa
## Call: fa(r = dta[, 1:11], nfactors = 2, rotate = "promax", fm = "pa")
## Standardized loadings (pattern matrix) based upon correlation matrix
## PA1 PA2 h2 u2 com
## y1 0.88 0.72 0.277 1.0
## y2 0.83 0.59 0.411 1.1
## y3 0.70 0.48 0.523 1.0
## y4 0.83 0.74 0.257 1.0
## y5 0.68 0.66 0.344 1.2
## y6 0.79 0.62 0.385 1.0
## y7 0.80 0.67 0.327 1.0
## y8 0.79 0.70 0.295 1.0
## x1 0.92 0.87 0.131 1.0
## x2 0.98 0.94 0.064 1.0
## x3 0.89 0.75 0.247 1.0
##
## PA1 PA2
## SS loadings 5.04 2.70
## Proportion Var 0.46 0.25
## Cumulative Var 0.46 0.70
## Proportion Explained 0.65 0.35
## Cumulative Proportion 0.65 1.00
##
## With factor correlations of
## PA1 PA2
## PA1 1.00 0.49
## PA2 0.49 1.00
##
## Mean item complexity = 1
## Test of the hypothesis that 2 factors are sufficient.
##
## The degrees of freedom for the null model are 55 and the objective function was 9.74 with Chi Square of 677.07
## The degrees of freedom for the model are 34 and the objective function was 0.84
##
## The root mean square of the residuals (RMSR) is 0.04
## The df corrected root mean square of the residuals is 0.05
##
## The harmonic number of observations is 75 with the empirical chi square 14.95 with prob < 1
## The total number of observations was 75 with Likelihood Chi Square = 57.06 with prob < 0.0079
##
## Tucker Lewis Index of factoring reliability = 0.939
## RMSEA index = 0.094 and the 90 % confidence intervals are 0.049 0.138
## BIC = -89.74
## Fit based upon off diagonal values = 0.99
## Measures of factor score adequacy
## PA1 PA2
## Correlation of (regression) scores with factors 0.97 0.98
## Multiple R square of scores with factors 0.94 0.96
## Minimum correlation of possible factor scores 0.88 0.93
fa.parallel(dta[, 1:11], fa = "pc", show.legend = FALSE)
## Parallel analysis suggests that the number of factors = NA and the number of components = 2
#建議分成兩個因素。若分成2個因素,特徵值皆會大於1
#準則:高fl,高h2,低u2,接近1的com
#共有PA1, PA2兩個因素
#x1/x2/x3這三個items分配到PA2這個factor,且都是高fl高h2低u2,接近1的com,三題都保留
#y1~y8這八個items分配到PA1這個factor,其中去掉fl較低的y5、低h2高u2的y3
#最後保留的items有9個,x1、x2、x3分配到PA2;y1、y2、y4、y6、y7、y8分配到PA1