吴裕雄--天生自然 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 # # ...
 
随机推荐
- 吴裕雄--天生自然 JAVA开发学习:正则表达式
			
import java.util.regex.*; class RegexExample1{ public static void main(String args[]){ String conten ...
 - Ubuntu 安装软件时显示:无法获得锁 /var/lib/dpkg/lock -open(资源暂时不可用)
			
出错状况:在用 sudo apt-get install 安装软件时,结果终端提示: 无法获得锁 /var/lib/dpkg/lock -open(资源暂时不可用) 无法锁定管理目录(var/lib/ ...
 - StdinNotImplementedError: raw_input was called, but this frontend does not support input requests.
			
当时VS CODE内嵌的jupyter 交互界面的时候,出现了这个错误 原因是,这样的界面不支持行输入.可以使用cmd终端或其他方式运行该文件进行交互输入
 - PowerShell创建 Profile
			
profile主要用于个性化常用的函数.别名等等.每次加载powershell的时候,都会执行profile中的内容. 查看是否有profile: $profile 如果结果是false说明没有.则创 ...
 - JavaEE--分布式对象
			
参考:http://blog.csdn.net/smcwwh/article/details/7080997 1.客户与服务器的角色 所有分布式编程技术的基本思想都很简单:客户计算机产生一个请求,然后 ...
 - LCA 最近公共祖先 Tarjan(离线)算法的基本思路及其算法实现
			
首先是最近公共祖先的概念(什么是最近公共祖先?): 在一棵没有环的树上,每个节点肯定有其父亲节点和祖先节点,而最近公共祖先,就是两个节点在这棵树上深度最大的公共的祖先节点. 换句话说,就是两个点在这棵 ...
 - mysql引擎与物理文件
			
SELECT VERSION();show GLOBAL VARIABLES like '%PARTITION%';-- 查看分区情况 show GLOBAL VARIABLES like '%dat ...
 - C++ malloc()函数的注意点及使用示例
			
1.malloc()函数的头文件是stdlib.h,其函数声明如下: void* malloc(size_t size); 其中参数size_t size表示动态内存分配空间的大小,以字节为单位. s ...
 - xcode6 Images.xcassets添加LaunchImage
			
不使用LaunchScreen.xib,通过Images.xcassets新建LaunchImage做登陆界面 步骤: 1.创建LaunchImage
 - mysql SQL优化琐记之索引
			
equal最好了,其次in,最后是range != <> 这类非操作尽量不用,它会转换为range.>都是范围查询 复合索引有左匹配原则,(clo_a,clo_b)相当建立了两个 ...