吴裕雄--天生自然 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 # # ...
随机推荐
- PAT Advanced 1010 Radix(25) [⼆分法]
题目 Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The ...
- PIL库参考文档之Image模块
原文: https://pillow-cn.readthedocs.io/zh_CN/latest/reference/Image.html 中文版参考文档不全,所以自己试着翻译了一下,以下~备注部分 ...
- 豆瓣爬虫Scrapy“抄袭”改写
主要是把项目从docker里面扒拉出来,但是扒拉完好像又没有什么用,放在docker里面运行多好. 源码下载下面主要记一下改动的地方吧. 配置:在database.py中改掉自己的数据库配置. 表结构 ...
- python语法基础-并发编程-线程-线程理论和线程的启动
####################### 线程介绍 ############################## """ 线程介绍 为什 ...
- latex学习笔记----基本知识、文档排版
1.空格和制表符等空白字符视为相同的空白距离,多个连续的空白字符等同为一个字符. 2.# $ % ^ _ { } ~ 在这些字符前面加上反斜线,就可以在文本中得到它们. 反斜线\不 ...
- 创造新时代!谷歌、微软、Facebook等巨头推出全新数据计划的背后
对于所有互联网企业来说,用户及其数据都是最核心.最根本的宝贵财富.因此,每家互联网企业都不会轻易将自家的数据与别人分享.试想一下,阿里会将淘宝和天猫的数据共享给京东吗?腾讯会把QQ和微信的数据分享给微 ...
- C盘满了解决办法之pagefile.sys文件
pagefile.sys文件一般存在于C盘,只有点击了隐藏属性才能看见. 这个文件一般比较大,它是系统创建虚拟内存页面的文件.平时大家使用软件的时候对于产生大量的临时数据,这些数据需要占用大量内存,如 ...
- myeclipse跟tomcat的同步
一般来说,我们在myeclipse里把文件内容改了并保存之后,直接刷新网页就可以非常直观的看到内容的改变. 这是因为myeclipse检测到文件内容的变动,及时地把新的文件部署到了tomcat上. m ...
- [Shoi2013]超级跳马(DP+矩阵乘法)
设f[i][j]表示方案数,显然有一个O(m2n)的暴力DP法,但实际上可以按距离当前位置的奇偶性分成s1[i][j]和s2[i][j],然后这个暴力DP可以优化到O(nm)的暴力.于是有这样的递推式 ...
- SOA,ROA 比较
1.SOA 面向服务架构 业务被抽象成服务 SOA架构中的对外服务一般都由web service来暴露 SOA架构中的内部服务一般由某种高效的RPC调用来暴露,当然了 也可以用web service来 ...