Clean
rm(list = ls()); graphics.off()
Set R packages path and load packages
.libPaths("C:/Rpack")
library(SensoMineR)
## Loading required package: FactoMineR
library(openxlsx)
library(FactoMineR)
Import data
bread_qda <- read.xlsx("DAdata.xlsx", sheet = 1)
head(bread_qda)
## assessor product replicate Hue Intensity Whiteness Saltiness Spice Bitterness
## 1 A8 P1 R1 3 3 8 7 1 1
## 2 A8 P1 R2 3 2 5 5 1 1
## 3 A8 P2 R1 3 3 8 7 1 1
## 4 A8 P2 R2 2 2 8 6 1 1
## 5 A8 P3 R1 1 1 9 7 3 1
## 6 A8 P3 R2 2 1 9 6 3 1
## Hardness Crispness Fatness
## 1 3 6 6
## 2 5 4 7
## 3 2 5 5
## 4 7 7 6
## 5 3 7 5
## 6 2 5 5
Run analyses
PCA
Generate averaged data
res.decat <- decat(qda, formul="~product+assessor", firstvar=4,
lastvar=ncol(qda), graph=F)
qda_m <- res.decat$adjmean
qda_m
## Hue Intensity Whiteness Saltiness Spice Bitterness Hardness Crispness
## P1 4.4375 4.4375 5.0000 4.8125 2.1250 1.4375 5.0000 5.8125
## P2 2.3750 2.6875 7.2500 5.3750 1.8750 1.3125 4.7500 5.1875
## P3 2.0625 2.0000 7.8750 5.1250 3.6875 1.3125 3.0000 4.3750
## P4 6.5000 6.6250 3.1250 5.1250 2.3750 1.9375 7.8125 7.3750
## P5 2.6875 2.9375 6.6250 6.2500 3.6250 1.8750 5.8125 6.7500
## P6 7.8750 7.2500 2.5625 4.1250 5.5625 2.0625 4.8750 5.6250
## Fatness
## P1 5.5625
## P2 4.7500
## P3 4.0625
## P4 6.2500
## P5 4.5000
## P6 5.2500
Apply PCA
res.pca <- PCA(qda_m, graph = FALSE)
res.dimdesc <- dimdesc(res.pca)
Plot PCA results
windows(10,10)
plot(res.pca, axes = c(1,2), choix = "ind", col.var = "blue", graph.type="classic")

# savePlot("PCA scores", type = "tif")
windows(10,10)
plot(res.pca, axes = c(1,2), choix = "var", col.var = "red", graph.type="classic")

# savePlot("PCA loadings", type = "tif")
Spider plot
Install package and set up
library(fmsb)
RNGkind("Mersenne-Twister")
set.seed(123)
maxmin <- t(data.frame(rep(9,ncol(qda_m)), rep(1,ncol(qda_m))))
rownames(maxmin) <- c("max", "min")
colnames(maxmin) <- colnames(qda_m)
dat <- as.data.frame(rbind(maxmin,qda_m))
cols <- c("red", "lightblue", "forestgreen", "purple",
"hotpink", "chocolate4", "orange", "steelblue",
"grey", "green", "khaki", "black")
Plot spider-plot
windows(10,10)
radarchart(dat, axistype=0, seg=4, plty=1, vlabels= colnames(dat),
title="Spider plot", vlcex=1,
pcol = cols, plwd = 2)
legend("topright",
legend = rownames(dat)[3:nrow(dat)],
bty = "n", pch = 20, col = cols,
text.col = cols, pt.cex = 2)

# savePlot("Spider plot", type = "tif")