# R - Principal Component Analysis

## 3 - Function

`prcomp `

Package stats

## 4 - Steps

### 4.1 - Perform the analysis

`pcaData = prcomp(USArrests, scale=TRUE)`

where:

• scale=TRUE will standardize the variables in order to take into account the different unity.

### 4.2 - Review the principal component data

• The data
`pcaData`
```Standard deviations:
[1] 1.5748783 0.9948694 0.5971291 0.4164494

Rotation:
PC1        PC2        PC3         PC4
Murder   -0.5358995  0.4181809 -0.3412327  0.64922780
Assault  -0.5831836  0.1879856 -0.2681484 -0.74340748
UrbanPop -0.2781909 -0.8728062 -0.3780158  0.13387773
Rapee    -0.5434321 -0.1673186  0.8177779  0.08902432```
• The variables associated (names)
`names(pcaData)`
`[1] "sdev"     "rotation" "center"   "scale"    "x"`
• Unclass will show the data :)
`unclass(pcaData)`
```\$sdev
[1] 1.5748783 0.9948694 0.5971291 0.4164494

\$rotation
PC1        PC2        PC3         PC4
Murder   -0.5358995  0.4181809 -0.3412327  0.64922780
Assault  -0.5831836  0.1879856 -0.2681484 -0.74340748
UrbanPop -0.2781909 -0.8728062 -0.3780158  0.13387773
Rapee    -0.5434321 -0.1673186  0.8177779  0.08902432

\$center
Murder  Assault UrbanPop     Rapee
7.788  170.760   65.540   21.232

\$scale
Murder   Assault  UrbanPop      Rapee
4.355510 83.337661 14.474763  9.366385

\$x
PC1         PC2         PC3          PC4
Alabama        -0.97566045  1.12200121 -0.43980366  0.154696581
`biplot(pcaData, scale=0)`