Post date: Nov 16, 2019 2:11:32 AM
In the precedent post, I was performing one PCA calculation after separating the small and big trees.
Now I perform the PCA with everyone and separate after.
Plot can be found here.
##########################################
### Doing the PCA before separating B and S trees
data_4 <- cbind(size,pairs,data)
res.pca <- prcomp(data_4[,-c(1,2,3,4)], center = TRUE)
# Separate trees by size: S and B
# Keep indices
indS <- which(data_4[,1]=="S")
indB <- which(data_4[,1]=="B")
pairsS <- as.character(data_4[indS,2])
pairsB <- as.character(data_4[indB,2])
PCA1.S <- res.pca$x[indS,1]
PCA1.B <- res.pca$x[indB,1]
# Compare S to B and keep the indices of S that are found in B
ind <- is.element(pairsS,pairsB)
# sim = similar
PCA1.S.sim <- PCA1.S[ind]
pairsS <- pairsS[ind]
# Store unique values for S
x <- unique(pairsS)
# Compare B to the new S, and keep of B the values found in S
ind <- is.element(pairsB,pairsS)
PCA1.B.sim <- PCA1.B[ind=="TRUE"]
pairsB <- pairsB[ind]
# Store unique values for B
y <- unique(pairsB)
# Compare new B and new S
setequal(x,y)
#################################
# Try the same plot without calculating means.
PCA1.S.uniq <- PCA1.S.sim[-c(3,4)]
PCA1.B.uniq <- PCA1.B.sim
plot(PCA1.S.uniq,PCA1.B.uniq,
xlim = c(-40,40),
ylim = c(-40,40),
xlab = "PC1 value for Small trees",
ylab = "PC1 value for Big trees") +
abline(seq(-40:40),seq(-40:40))