Compute AHC on Lexical table without using an intermediate CA
Compute AHC on Lexical table without using an intermediate CA should be possible with FactoMineR.
with our current version of R and FactoMineR the following code fails :
m <- matrix(c(1,2,3,4,5,6,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,6,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41), ncol=5);
HCPC(m, graph=FALSE)
ERROR MESSAGE : Erreur dans res.sauv$call : $ operator is invalid for atomic vectors
R VERSION : 4.2.2 (2022-10-31)
FactoMineR VERSION : 2023-03-27 06:55:37 UTC; husson
Solution
Test with newer version ? ---> NO
HCPC works with a "result of a factor analysis or a dataframe" the solution is to convert the Lexical Table matrix to a data frame:
HCPC(data.frame(LexicalTable123), graph=FALSE)
HCPC results are very different:
m <- matrix(c(1,2,3,4,5,6,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,6,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,1,2,3,4,5), ncol=5);
colnames(m) <- c("c1", "c2", "c3", "c4", "c5");
hm <-HCPC(data.frame(t(m)), graph=FALSE, nb.clust=4, consol=FALSE);
hca <-HCPC(CA(m, graph=FALSE), cluster.CA="columns", graph=FALSE, nb.clust=4, consol=FALSE);
svg(file="~/hm.svg");
plot(hm, choice="tree");
dev.off();
svg(file="~/hca.svg");
plot(hca, choice="tree");
dev.off();
FactoMineR CODE to manage data.frame :
if (is.data.frame(res)){
res <- res[,unlist(lapply(res,is.numeric)),drop=FALSE]
### AJOUT K-means
if (kk<nrow(res)) kk <- min(kk,nrow(unique(res)))
if (kk <= nrow(res)){
cla <- kmeans(res, centers=kk, iter.max = 100, nstart = 4)
res <- PCA(cla$centers, row.w=cla$size, scale.unit = FALSE, ncp = Inf, graph = FALSE)
} else {
res <- PCA(res, scale.unit = FALSE, ncp = Inf, graph = FALSE)
}
### `Fin AJOUT K-means`
## `res <- PCA(res, scale.unit = FALSE, ncp = Inf, graph = FALSE)`
}
Validation test
- Compute an AHC directly on VOEUX/loc
- Show hidden parents of the AHC (corpus view contextual menu)
- direct parent is a Lexical table
- check the AHC with the Informations panels
