This video explains how to apply a Principal Component Analysis (PCA) in R. More details: [ Ссылка ]
The video is presented by Cansu Kebabci, a data scientist and statistician at Statistics Globe. Find more information about Cansu here: [ Ссылка ]
In the video, Cansu explains the steps and application of the Principal Component Analysis in R. Watch the video to learn more on this topic!
Here can you find the first part of this series:
Introduction to Principal Component Analysis (Pt. 1 - Theory): [ Ссылка ]
Links to the tutorials mentioned in the video:
Can PCA be Used for Categorical Variables? (Alternatives & Example): [ Ссылка ]
PCA Using Correlation & Covariance Matrix (Examples): [ Ссылка ]
Biplot of PCA in R (Examples): [ Ссылка ]
R code of this video:
# install.packages("MASS")
# install.packages("factoextra")
# install.packages("ggplot2")
# Load Libraries
library(MASS)
library(factoextra)
library(ggplot2)
# Import biopsy data
data(biopsy)
dim(biopsy)
# Structure of Data
str(biopsy)
summary(biopsy)
# Delete Cases with Missingness
biopsy_nomiss <- na.omit(biopsy)
# Exclude Categorical Data
biopsy_sample <- biopsy_nomiss[,-c(1,11)]
# Run PCA
biopsy_pca <- prcomp(biopsy_sample,
scale = TRUE)
# Summary of Analysis
summary(biopsy_pca)
# Elements of PCA object
names(biopsy_pca)
# Std Dev of Components
biopsy_pca$sdev
# Eigenvectors
biopsy_pca$rotation
# Std Dev and Mean of Variables
biopsy_pca$center
biopsy_pca$scale
# Principal Component Scores
biopsy_pca$x
# Scree Plot of Variance
fviz_eig(biopsy_pca,
addlabels = TRUE,
ylim = c(0, 70))
# Biplot with Default Settings
fviz_pca_biplot(biopsy_pca)
# Biplot with Labeled Variables
fviz_pca_biplot(biopsy_pca,
label="var")
# Biplot with Colored Groups
fviz_pca_biplot(biopsy_pca,
label="var",
habillage = biopsy_nomiss$class)
# Biplot with Customized Colored Groups and Variables
fviz_pca_biplot(biopsy_pca,
label="var",
habillage = biopsy_nomiss$class,
col.var = "black") +
scale_color_manual(values=c("orange", "purple"))
Follow me on Social Media:
Facebook – Statistics Globe Page: [ Ссылка ]
Facebook – R Programming Group for Discussions & Questions: [ Ссылка ]
Facebook – Python Programming Group for Discussions & Questions: [ Ссылка ]
LinkedIn – Statistics Globe Page: [ Ссылка ]
LinkedIn – R Programming Group for Discussions & Questions: [ Ссылка ]
LinkedIn – Python Programming Group for Discussions & Questions: [ Ссылка ]
Twitter: [ Ссылка ]
Instagram: [ Ссылка ]
TikTok: [ Ссылка ]
![](https://i.ytimg.com/vi/mNpBrHwOCt4/maxresdefault.jpg)