0
$\begingroup$

I am working with dental metric data to perform a biological distance analysis. The standard procedure in my field is to perform a PCA on the cleaned, imputed dataset to reduce correlation and then determine Mahalanobis Distance for each individual in the dataset. I've never done this type of analysis before, and I'm assuming it must be so obvious, because no one really explains how they move from Step 1 to Step 2.

I've completed a PCA using FactoMineR in R on my dataset; I'm keeping the first four principal components, which all have eigenvalues >1 (the standard in my field). However, I don't know what output from the PCA I should keep to run the distance analysis. The PCA function returns 3 values for individuals: coordinates for each dimension, cos2 for each dimension, and contribution for each dimension.

I'm guessing it's coordinates, but I'd rather be sure before I move on.

$\endgroup$

1 Answer 1

1
$\begingroup$

Yes it is under $ind$coord. You need to subset the columns based on the cut off you defined, for example:

library(FactoMineR)
res.pca <- PCA(iris[,1:4], scale.unit=TRUE, graph = FALSE)
# here i am using 0.5 not 1
keep = res.pca$eig[,1] > 0.5
PCs = res.pca$ind$coord[,keep]

Not very sure what kind of m you are calculating, but let's say we go for pairwise, using the solution from this post

cholMaha <- function(X) {
 dec <- chol( cov(X) )
 tmp <- forwardsolve(t(dec), t(X) )
 dist(t(tmp))
}
pairwise_Ma = cholMaha(PCs)

And simple cluster:

plot(PCs[,1:2],col=factor(kmeans(pairwise_Ma,3)$cluster))

enter image description here

$\endgroup$
2
  • $\begingroup$ Awesome, thank you! I am calculating pairwise, and the code worked perfectly. $\endgroup$ Commented May 23, 2020 at 17:47
  • $\begingroup$ you're welcome ! glad it works for u $\endgroup$
    – StupidWolf
    Commented May 27, 2020 at 18:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.