library(tidyverse)
## -- Attaching packages -------------------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.0 v purrr 0.3.4
## v tibble 3.0.1 v dplyr 0.8.5
## v tidyr 1.0.3 v stringr 1.4.0
## v readr 1.3.1 v forcats 0.5.0
## -- Conflicts ----------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(FactoMineR)
library(factoextra)
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
setwd("C:/Users/19419/OneDrive - Washington State University (email.wsu.edu)/WSU/SMOKE/Stone Tree Bin Trials")
# read in the data
smkDA <- read.csv("bucket sensory gc wine collab.csv", header = TRUE)
smkDA2 <- column_to_rownames(smkDA,var="Sample")
res.MFA <- MFA(smkDA2,
group = c(2,5,6,11,7,3),
type = c("n","s","s","s","s","s"),
name.group = c("origin","basic chemistry","phenolics","odor intensity", "taste","smoke taint"),
num.group.sup = 1,
graph = FALSE)
print(res.MFA)
## **Results of the Multiple Factor Analysis (MFA)**
## The analysis was performed on 16 individuals, described by 34 variables
## *Results are available in the following objects :
##
## name description
## 1 "$eig" "eigenvalues"
## 2 "$separate.analyses" "separate analyses for each group of variables"
## 3 "$group" "results for all the groups"
## 4 "$partial.axes" "results for the partial axes"
## 5 "$inertia.ratio" "inertia ratio"
## 6 "$ind" "results for the individuals"
## 7 "$quanti.var" "results for the quantitative variables"
## 8 "$quali.var.sup" "results for the categorical supplementary variables"
## 9 "$summary.quanti" "summary for the quantitative variables"
## 10 "$summary.quali" "summary for the categorical variables"
## 11 "$global.pca" "results for the global PCA"
####Scree Plot
fviz_screeplot(res.MFA)
group <- get_mfa_var(res.MFA, "group")
group
## Multiple Factor Analysis results for variable groups
## ===================================================
## Name Description
## 1 "$coord" "Coordinates"
## 2 "$cos2" "Cos2, quality of representation"
## 3 "$contrib" "Contributions"
## 4 "$correlation" "Correlation between groups and principal dimensions"
fviz_mfa_var(res.MFA, "group")
fviz_contrib(res.MFA, "group", axes = 1)
fviz_contrib(res.MFA, "group", axes = 2)
quanti.var <- get_mfa_var(res.MFA, "quanti.var")
quanti.var
## Multiple Factor Analysis results for quantitative variables
## ===================================================
## Name Description
## 1 "$coord" "Coordinates"
## 2 "$cos2" "Cos2, quality of representation"
## 3 "$contrib" "Contributions"
fviz_mfa_var(res.MFA, "quanti.var", palette = "jco",
col.var.sup = "violet", repel = TRUE,
geom = c("point", "text"), legend = "bottom")
fviz_contrib(res.MFA, choice = "quanti.var", axes = 1, top = 20,
palette = "jco")
fviz_contrib(res.MFA, choice = "quanti.var", axes = 2, top = 20,
palette = "jco")
fviz_mfa_var(res.MFA, "quanti.var", col.var = "contrib",
gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
col.var.sup = "violet", repel = TRUE,
geom = c("point", "text"))
ind <- get_mfa_ind(res.MFA)
ind
## Multiple Factor Analysis results for individuals
## ===================================================
## Name Description
## 1 "$coord" "Coordinates"
## 2 "$cos2" "Cos2, quality of representation"
## 3 "$contrib" "Contributions"
## 4 "$coord.partiel" "Partial coordinates"
## 5 "$within.inertia" "Within inertia"
## 6 "$within.partial.inertia" "Within partial inertia"
fviz_mfa_ind(res.MFA,
habillage = "Varietal",
palette = c("#00AFBB", "#E7B800", "#FC4E07","green"),
repel = TRUE,
label = FALSE)
fviz_mfa_ind(res.MFA,
habillage = "Varietal", # color by groups
palette = c("#00AFBB", "#E7B800", "#FC4E07","green"),
addEllipses = TRUE, ellipse.type = "confidence",
repel = TRUE # Avoid text overlapping
)
fviz_ellipses(res.MFA, c("Varietal", "Block"), repel = TRUE)
fviz_mfa_axes(res.MFA, repel = TRUE)