R language PCA

Source: Internet
Author: User

1, Key points

Summary: Principal component analysis analysis of canonical correlation, the common denominator of three methods is to extract some common parts from data, and then analyze and deal with these public parts.


#主成分分析 is a statistical analysis method to convert multi-indexes into a few synthetic indexes

Principal component analysis is a method of reducing the number of variables into a few principal components by means of dimensionality reduction, which can reflect most of the information of the original variables, which are usually expressed as linear combinations of the original variables.

2. Function Summary

#R中作为主成分分析最主要的函数是princomp () function
#princomp () Principal component analysis can be analyzed from related matrices or from covariance matrix
#summary () extracting principal component information
#loadings () Displays the contents of the load in principal component analysis or factor analysis
#predict () Predict the value of the principal component
#screeplot () plot the main component of the gravel
#biplot () draw data about the main component of the scatter plot and the original coordinates under the principal component direction

3. Case

#现有30名中学生身高, body weight, bust, sitting height data, the body of the four indicators of data analysis of the master component.

#1. Loading raw data
Test<-data.frame (
X1=c (148, 139, 160, 149, 159, 142, 153, 150, 151, 139,
140, 161, 158, 140, 137, 152, 149, 145, 160, 156,
151, 147, 157, 147, 157, 151, 144, 141, 139, 148),
X2=c (41, 34, 49, 36, 45, 31, 43, 43, 42, 31,
29, 47, 49, 33, 31, 35, 47, 35, 47, 44,
42, 38, 39, 30, 48, 36, 36, 30, 32, 38),
X3=c (72, 71, 77, 67, 80, 66, 76, 77, 77, 68,
64, 78, 78, 67, 66, 73, 82, 70, 74, 78,
73, 73, 68, 65, 80, 74, 68, 67, 68, 70),
X4=c (78, 76, 86, 79, 86, 76, 83, 79, 80, 74,
74, 84, 83, 77, 73, 79, 79, 77, 87, 85,
82, 78, 80, 75, 88, 80, 76, 76, 73, 78)
)

#2. Principal component analysis and display of analysis results
Test.pr<-princomp (test,cor=true) #cor是逻辑变量当cor =true means analysis of the correlation matrix R of the sample

                                                                                         when Cor=false represents the covariance matrix s of the sample, the component analysis
Summary (test.pr,loadings=true)   #loading是逻辑变量当loading =true indicates the contents of the loading are displayed

#loadings的输出结果为载荷是主成分对应于原始变量的系数即Q矩阵

Meaning of the analysis result
#----Standard deviation the squared variance = eigenvalues
#----Proportion of Variance variance contribution rate
#----Cumulative Proportion Variance Cumulative contribution rate


The cumulative contribution rate of the first two principal components of the #由结果显示 has reached 96% and the other two principal components can be reduced to achieve dimensionality reduction.

So you can get the function expression z1=-0.497x ' 1-0.515x ' 2-0.481x ' 3-0.507x ' 4

z2= 0.543X ' 1-0.210x ' 2-0.725x ' 3-0.368x ' 4

#4. Plot the main component of the gravel and predict

Screeplot (test.pr,type= "lines")

P<-predict (TEST.PR)

It can be seen from the gravel plot that the second principal component follows a smooth line change so that the first two principal components can be selected for analysis.

R language PCA

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.