吴裕雄--天生自然 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 # # ...
随机推荐
- 在阿里做了5年技术Leader,我总结出这些套路!
转自 51CTO技术栈 内容 团队建设 团队管理 团队文化 沟通与辅导 招聘与解雇 互联网公司的技术团队管理通常分为两个方向:技术管理和团队管理,互联网公司的技术 TL 与传统软件公司的 PM 还是有 ...
- linux配置词典goldendict
在mint 18下使用通过, ubuntu 类似. 方法: 通过软件中心安装goldendict,或者 sudo apt install goldendict 通过网页抓取程序, 见附录 下载朗道词典 ...
- 【PXC】关于限流的参数,状态值说明
一.什么是流控(FC)?如何工作? 节点接收写集并把它们按照全局顺序组织起来,节点将接收到的未应用和提交的事务保存在接收队列中,当这个接收队列达到一定的大小,将触发限流:此时节点将暂停复制,节点会先处 ...
- 吴裕雄--天生自然 PHP开发学习:连接 MySQL、创建表
<?php $servername = "localhost"; $username = "root"; $password = "admin& ...
- IOC与AOP的理解
转自 https://blog.csdn.net/qq_38006047/article/details/80797386 1,理解“控制反转” 控制反转,也叫依赖注入,是面向对象编程中的一种设计理念 ...
- 后台用Hbase对表单数据实现增删改查遇到的问题
1.无法解析jsp 原因:hbase中lib下jar包会与tomcat包冲突,需要删除与tomcat冲突的包 这是我删除的几个包 之后运行就没有问题了 2.对于Hbase修改的问题 在添加数据时,HB ...
- ant design for vue select 数据回显问题
例如: 想要回显id为1的温度, 结果直接在select框中显示了1,而不是选中了温度, 此时因为select中的value是string类型, 而我们设置的id是number类型, 对应不上, 所以 ...
- 测试mvn -v 时报错,原因
当安装完maven后在cmd命令框通过mvn -v 可以判断maven环境变量是否安装成功,但我安装配置完环境变量后执行报错如图 原因:配置的jdk的环境变量不符合maven最低要求(我配置的是jdk ...
- 小白安装Android Studio
原文 Android Studio 安装 步骤1 - 系统要求 可以在以下的操作系统开始 Android 应用程序开发: Microsoft® Windows® 8/7/Vista/2003 (32 ...
- Spire.doc jar包实现word文件添加水印demo
/** * @create: 2020-02-23 21:50 */ import com.spire.doc.*; import com.spire.doc.documents.WatermarkL ...