This video explains how to apply a Principal Component Analysis (PCA) in R. More details: https://statisticsglobe.com/principal-component-analysis-r
The video is presented by Cansu Kebabci, a data scientist and statistician at Statistics Globe. Find more information about Cansu here: https://statisticsglobe.com/cansu-kebabci
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): https://www.youtube.com/watch?v=DngS4LNNzc8
Links to the tutorials mentioned in the video:
Can PCA be Used for Categorical Variables? (Alternatives & Example): https://statisticsglobe.com/pca-categorical-variables
PCA Using Correlation & Covariance Matrix (Examples): https://statisticsglobe.com/pca-correlation-covariance-matrix
Biplot of PCA in R (Examples): https://statisticsglobe.com/biplot-pca-r
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: https://www.facebook.com/statisticsglobecom/
Facebook – R Programming Group for Discussions & Questions: https://www.facebook.com/groups/statisticsglobe
Facebook – Python Programming Group for Discussions & Questions: https://www.facebook.com/groups/statisticsglobepython
LinkedIn – Statistics Globe Page: https://www.linkedin.com/company/statisticsglobe/
LinkedIn – R Programming Group for Discussions & Questions: https://www.linkedin.com/groups/12555223/
LinkedIn – Python Programming Group for Discussions & Questions: https://www.linkedin.com/groups/12673534/
Twitter: https://twitter.com/JoachimSchork
Instagram: https://www.instagram.com/statisticsglobecom/
TikTok: https://www.tiktok.com/@statisticsglobe