R 스크립트: 탐색적 분석, 크론바하 신뢰도, 요인분석

# 탐색적분석
# 내장 데이터 attitude를 사용합시다.
# 큰 재무조직의 피고용인을 대상으로 한 데이터입니다.


# FUNCTION DEFINITIONS
f_chk_packages <- function() {
  if(! require(psych, quietly = T)) install.packages("psych")
  if(! require(GPArotation, quietly = T)) install.packages("GPArotation") 
}

f_des <- function(x) {
  f_chk_packages()
  cat("START =====================\n")
  print(describe(x))
  cat("END =====================\n")
}
f_cor <- function(x) {
  cat("START =====================\n")
  print(corr.test(x))
  pairs.panels(x)
  cor.plot(cor(x))
  cat("END =====================\n")
}
f_factor <- function(x) {
  print(alpha(x))
#   nfactors : 요인의 수
#   rotate   : 요인의 회전 방법 (varimax,oblimin,...)
#   fm       : 알고리즘 (minres, wls, gls, pa, ml) 차례로 OLS, WLS, GLS, principle component, maximum likelihood

  print(
    fa(x,
       nfactors=2,
       rotate="varimax",
       fm="pa")
  )
}

# SAMPLE SCRIPT
head(attitude)
f_des(attitude)
f_cor(attitude)
f_factor(attitude)

댓글

이 블로그의 인기 게시물

R에서 csv 파일 읽는 법

xlwings tutorial - 데이터 계산하여 붙여 넣기