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

Panel performance

ANOVA model

qda <- as.data.frame(bread_qda)
res.pp <- panelperf(qda, firstvar=4, formul="~product+assessor+replicate+ product:assessor+product:replicate+assessor:replicate")
p.value <- res.pp$p.value
p.value
##            product            assessor           replicate         
## Hue              1.594292e-13       1.641190e-04          0.8667318
## Intensity        6.859327e-16       1.428904e-05          0.7910052
## Whiteness        8.911465e-15       3.319416e-06          0.8619209
## Saltiness        9.358085e-02       2.739611e-05          0.2988723
## Spice            1.877678e-06       7.952131e-13          0.3200119
## Bitterness       1.772001e-01       7.739878e-10          0.1945945
## Hardness         5.951338e-08       6.928288e-05          0.1500957
## Crispness        1.434990e-04       1.956800e-05          0.6682310
## Fatness          1.134765e-02       3.057369e-06          0.8182805
##            product:assessor   product:replicate  assessor:replicate
## Hue              6.382259e-07          0.4596379         0.55454349
## Intensity        2.047463e-03          0.3998635         0.03276646
## Whiteness        1.590794e-01          0.7276830         0.03307057
## Saltiness        1.607340e-02          0.7490344         0.26589052
## Spice            1.429352e-04          0.5305475         0.88122935
## Bitterness       6.098997e-05          0.1486547         0.01579670
## Hardness         1.080251e-01          0.5466320         0.49226407
## Crispness        1.684461e-02          0.3822134         0.99130389
## Fatness          6.327374e-03          0.5534993         0.74357779

Plot and save ANOVA table

windows(10,10)
coltable(p.value[order(p.value[,1]),], col.lower="gray")

# savePlot("ANOVA tab", type = "tif")

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")