0
votes

I need to compute Hotelling T2 and SPE (Q), after the PCA analysis. I did it using the pca function from library mdatools, but I see the PC computed are different from the one computed by prcomp or princomp functions. Why?

library(mdatools)
NF4.3.pca4 <- pca(NF4.3, ncomp = 15, center = T, scale = T)
res <- NF4.3.pca4$calres

NF4.3.pca <- prcomp(NF4.3, center = T, scale. = T) #different eigenvalues

Is there another way to calculate T2 and SPE from principal components?

Data:

ASSORB_CAT1;ASSORB_CAT3;ASSORB_VOLANO;AZOTO_IN
0.03662109;23.55957;-12.30469;39.3
0;25.36621;-11.09619;39.2
-0.02441406;21.92383;-11.26709;39.2
-0.02441406;23.10791;-11.07178;39.1
-0.04882813;22.81494;-10.57129;39.59975
0;24.24316;-11.23047;39.89737
0;22.63184;-11.43799;39.8
-0.04882813;24.34082;-13.61084;39.5
0;21.83838;-11.1084;39.4
0;24.3042;-12.08496;39.3
0;24.67041;-12.40234;39.3
1

1 Answers

0
votes

I will explain on an other dataset, as I do not have access to what you are analysing. The two methods that you applied on my dataset are identical. What can be confusing though is that if you look at stats_pca$sdev it is a root square of the vector of eigenvalues, whereas mdatools_pca$eigenvals reports eigenvalues themselves.

library(mdatools)
data("mtcars")
stats_pca <- prcomp(mtcars, center=TRUE, scale.=TRUE)
mdatools_pca <- mdatools::pca(mtcars, center=TRUE, scale=TRUE)

all.equal(sqrt(mdatools_pca$eigenvals)[1:length(stats_pca$sdev)], stats_pca$sdev)
# TRUE

If you want to go on with Hotelling's T2 I would recommend this read: PCA and Hotelling's T^2 for confidence intervall in R.