一、美国法官评分的主成分分析
1 | #prepare data for PCA |
we can also do this in R by using the function named princomp1
2
3
4pca=princomp(data,cor=T,scores=T)
pca#show the result
#plot Garaval map
screeplot(pca,type='lines')
From the analysis,we can select the first two compnent as our principal compnent.
1 | summary=summary(pca, loadings = T) |
refer:https://blog.csdn.net/wangyajie_11/article/details/53785528
Now let’s use the result that we selected just now to do cluster analysis and discriminant analysis 1
2#cluster analysis
kmeans(new_data,center=3,iter.max=100,nstart=2333)
1 | #discriminant analysis |
二、应用以下R自带数据集进行因子分析。
use_data: state.x771
2library('psych')
fa(state.x77, nfactors = 2, score=c("regression"),rotate = "varimax", fm = "ml")
refer: https://www.jianshu.com/p/33ad4e2b29b3
三、R语言的作图
1.常用统计图
1 | mean=apply(USJudgeRatings,2,mean) |
1 | pie(mean) |
1 | boxplot(USJudgeRatings) |
1 | stars(USJudgeRatings) |
1 | #unable to download the library |
2.基础绘图命令
1 | plot(x <- rnorm(10), y=rnorm(10),type = "l", main = "main title",xlab='x axis',ylab='y axis',sub='sub title') |