0% found this document useful (0 votes)
7 views

PCA-411210002

The document presents a Principal Component Analysis (PCA) on the USArrests dataset, detailing the mean and variance of variables such as Murder, Assault, UrbanPop, and Rape. It includes the PCA output, including standard deviations, rotation, and the proportion of variance explained by each principal component. Visualizations of the proportion and cumulative proportion of variance explained by the principal components are also provided.

Uploaded by

hubertkuo418
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

PCA-411210002

The document presents a Principal Component Analysis (PCA) on the USArrests dataset, detailing the mean and variance of variables such as Murder, Assault, UrbanPop, and Rape. It includes the PCA output, including standard deviations, rotation, and the proportion of variance explained by each principal component. Visualizations of the proportion and cumulative proportion of variance explained by the principal components are also provided.

Uploaded by

hubertkuo418
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

PCA 411210002

2024-11-15
states=row.names(USArrests)

names(USArrests)

## [1] "Murder" "Assault" "UrbanPop" "Rape"

apply(USArrests, 2, mean)

## Murder Assault UrbanPop Rape


## 7.788 170.760 65.540 21.232

apply(USArrests, 2, var)

## Murder Assault UrbanPop Rape


## 18.97047 6945.16571 209.51878 87.72916

pr.out=prcomp(USArrests, scale. = TRUE)


names(pr.out)

## [1] "sdev" "rotation" "center" "scale" "x"

pr.out$center

## Murder Assault UrbanPop Rape


## 7.788 170.760 65.540 21.232

pr.out$scale

## Murder Assault UrbanPop Rape


## 4.355510 83.337661 14.474763 9.366385

pr.out$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
## Rape -0.5434321 0.1673186 -0.8177779 0.08902432

dim(pr.out$x)

## [1] 50 4

biplot(pr.out, scale=0)
pr.out$rotation=-pr.out$rotation
pr.out$x=-pr.out$x
biplot(pr.out, scale=0)
pr.out$sdev

## [1] 1.5748783 0.9948694 0.5971291 0.4164494

pr.var=pr.out$sdev^2
pr.var

## [1] 2.4802416 0.9897652 0.3565632 0.1734301

pve=pr.var/sum(pr.var)
pve

## [1] 0.62006039 0.24744129 0.08914080 0.04335752

plot(pve, xlab="Principal Component", ylab="Proportion of Variance


Explained", ylim=c(0, 1), type='b')

plot(cumsum(pve), xlab="Principal Component", ylab="Cumulative


Proportion of Variance Explained", ylim=c(0, 1), type='b')

You might also like