吴裕雄--天生自然 R语言开发学习:主成分分析和因子分析(续一)
#--------------------------------------------#
# R in Action (2nd ed): Chapter 14 #
# Principal components and factor analysis #
# requires package psych #
# install.packages("psych") #
#--------------------------------------------# par(ask=TRUE)
set.seed(1234) # make results reproducible # Listing 14.1 - Principal components analysis of US Judge Ratings
library(psych)
pc <- principal(USJudgeRatings[,-1], nfactors=1)
pc # Principal components analysis Harman23.cor data
library(psych)
fa.parallel(Harman23.cor$cov, n.obs=302, fa="pc", n.iter=100,
show.legend=FALSE, main="Scree plot with parallel analysis") # Listing 14.2 - Principal components analysis of body measurements
library(psych)
PC <- principal(Harman23.cor$cov, nfactors=2, rotate="none")
PC # Listing 14.3 - Principal components analysis with varimax rotation
rc <- principal(Harman23.cor$cov, nfactors=2, rotate="varimax")
rc # Listing 14.4 - Obtaining componenet scores from raw data
library(psych)
pc <- principal(USJudgeRatings[,-1], nfactors=1, score=TRUE)
head(pc$scores)
cor(USJudgeRatings$CONT, pc$score) # Listing 14.5 - Obtaining principal component scoring coefficients
library(psych)
rc <- principal(Harman23.cor$cov, nfactors=2, rotate="varimax")
round(unclass(rc$weights), 2) ## Exploratory factor analysis of ability.cov data options(digits=2)
library(psych)
covariances <- ability.cov$cov
# convert covariances to correlations
correlations <- cov2cor(covariances)
correlations # determine number of factors to extract
fa.parallel(correlations, n.obs=112, fa="both", n.iter=100,
main="Scree plots with parallel analysis") # Listing 14.6 - Principal axis factoring without rotation
fa <- fa(correlations, nfactors=2, rotate="none", fm="pa")
fa # Listing 14.7 - Factor extraction with orthogonal rotation
fa.varimax <- fa(correlations, nfactors=2, rotate="varimax", fm="pa")
fa.varimax # Listing 14.8 - Factor extraction with oblique rotation
fa.promax <- fa(correlations, nfactors=2, rotate="promax", fm="pa")
fa.promax # calculate factor loading matrix
fsm <- function(oblique) {
if (class(oblique)[2]=="fa" & is.null(oblique$Phi)) {
warning("Object doesn't look like oblique EFA")
} else {
P <- unclass(oblique$loading)
F <- P %*% oblique$Phi
colnames(F) <- c("PA1", "PA2")
return(F)
}
}
fsm(fa.promax) # plot factor solution
factor.plot(fa.promax, labels=rownames(fa.promax$loadings))
fa.diagram(fa.promax, simple=FALSE) # factor scores
fa.promax$weights
吴裕雄--天生自然 R语言开发学习:主成分分析和因子分析(续一)的更多相关文章
- 吴裕雄--天生自然 R语言开发学习:聚类分析(续一)
#-------------------------------------------------------# # R in Action (2nd ed): Chapter 16 # # Clu ...
- 吴裕雄--天生自然 R语言开发学习:时间序列(续三)
#-----------------------------------------# # R in Action (2nd ed): Chapter 15 # # Time series # # r ...
- 吴裕雄--天生自然 R语言开发学习:时间序列(续二)
#-----------------------------------------# # R in Action (2nd ed): Chapter 15 # # Time series # # r ...
- 吴裕雄--天生自然 R语言开发学习:时间序列(续一)
#-----------------------------------------# # R in Action (2nd ed): Chapter 15 # # Time series # # r ...
- 吴裕雄--天生自然 R语言开发学习:方差分析(续二)
#-------------------------------------------------------------------# # R in Action (2nd ed): Chapte ...
- 吴裕雄--天生自然 R语言开发学习:方差分析(续一)
#-------------------------------------------------------------------# # R in Action (2nd ed): Chapte ...
- 吴裕雄--天生自然 R语言开发学习:回归(续四)
#------------------------------------------------------------# # R in Action (2nd ed): Chapter 8 # # ...
- 吴裕雄--天生自然 R语言开发学习:回归(续三)
#------------------------------------------------------------# # R in Action (2nd ed): Chapter 8 # # ...
- 吴裕雄--天生自然 R语言开发学习:回归(续二)
#------------------------------------------------------------# # R in Action (2nd ed): Chapter 8 # # ...
- 吴裕雄--天生自然 R语言开发学习:回归(续一)
#------------------------------------------------------------# # R in Action (2nd ed): Chapter 8 # # ...
随机推荐
- 干货|Kubernetes集群部署
Nginx-ingress Controller
Kubernetes提供了两种内建的云端负载均衡机制用于发布公共应用,一种是工作于传输层的Service资源,它实现的是TCP负载均衡器:另一种是Ingress资源,它实现的是HTTP(S)负载均衡器 ...
- 吴裕雄--天生自然ShellX学习笔记:Shell简介
Shell 是一个用 C 语言编写的程序,它是用户使用 Linux 的桥梁.Shell 既是一种命令语言,又是一种程序设计语言. Shell 是指一种应用程序,这个应用程序提供了一个界面,用户通过这个 ...
- UML-为什么要画领域模型?
不熟悉业务的情况下, 1).找到关键概念和词汇 2).概念间的关系 熟悉业务的情况下, 1).梳理思路 完美不是目的. 另外,减少标示差异.如下图
- 内存管理-MRC
MRC内存管理 环境:先关闭arc模式,选中项目->build Settings
- 01.Java安装及环境变量的设置
1.下载 https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 2.mac上安装及配 ...
- JS导出、导入EXCEL(案例)
插件下载地址:http://oss.sheetjs.com/js-xlsx/xlsx.full.min.js 1.导出excel <!DOCTYPE html> <html> ...
- E - Rebuild UVALive - 7187 (二次函数极值问题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5531 Problem Description Archaeologists find ruins of ...
- Java复习(四)类的重用
4.1类的继承 Java只支持类的单继承,每一个子类只能有一个直接父类. #继承的语法 class childClass extends parentClass { //类体 } 子类不能直接访问从父 ...
- HDU-1540 Tunnel Warfare(区间连续点长度)
http://acm.hdu.edu.cn/showproblem.php?pid=1540 Time Limit: 4000/2000 MS (Java/Others) Memory Limi ...
- 31)PHP,对象的遍历
对象的遍历: 对象也可以可以使用foreach语句进行便利,有两点注意: 1,只能便利属性.(所以,这个就解决了,为啥之前的数据库类,我只是看到了一些属性名字,而没有得到我的属性值) 2,只能便利“看 ...