1
$\begingroup$

FactoMineR package is helpful when doing PCA and much more. Coming across the output using dimdesc() function and looking at the estimates of supplementary qualitative variables I didn't grasp the idea of how these estimates were calculated. After peeking into the code of the function, these estimates seem to be those of ANOVA test.

FactoMineR dimdesc()

FactoMineR::dimdesc
FactoMineR::condes

I found the relevant code in condes() function which was called from inside dimdesc() function.

...
res.aov <- aov(y ~ x, weights = w, na.action = na.exclude)
...
truncated
...
Estimate <- summary.lm(res.aov)$coef[-1, 1, drop = FALSE]
Estimate <- c(Estimate, -sum(Estimate))
...
truncated

MWE: Decathlon dataset

library(FactoMineR)
data(decathlon)
res.pca <- PCA(decathlon,quanti.sup=11:12,quali.sup=13)

Output of PCA by dimdesc() function

dimdesc(res.pca, proba = 0.2)

The estimates according to FactoMineR

Link between the variable and the categorical variable (1-way anova)
=============================================
                R2 p.value
Competition 0.0511  0.1553

Link between variable abd the categories of the categorical variables
================================================================
                     Estimate p.value
Competition=OlympicG   0.4394  0.1553
Competition=Decastar  -0.4394  0.1553

So as you can see, the qualitative variable (Competition) was a supplementary one, it doesn't contribute to constructing the very principal components of the PCA, they are just fed for descriptive and illustrative purposes.

My trial to verify the estimates manually

decathlon$PC1 <- res.pca$ind$coord[, 1] # attaching PC1 or Dim1 to the dataset

We use ANOVA test now:

resAOV <- aov(PC1 ~ Competition, data = decathlon, na.action = na.exclude)
summary.lm(resAOV)

Output:

> summary.lm(resAOV)
    
    Call:
aov(formula = PC1 ~ Competition, data = decathlon, na.action = na.exclude)

Residuals:
   Min     1Q Median     3Q    Max 
-3.379 -0.961 -0.009  0.957  4.341 

Coefficients:
                    Estimate Std. Error t value Pr(>|t|)
(Intercept)           -0.600      0.501   -1.20     0.24
CompetitionOlympicG    0.879      0.606    1.45     0.16

Residual standard error: 1.81 on 39 degrees of freedom
Multiple R-squared:  0.0511,    Adjusted R-squared:  0.0268 
F-statistic:  2.1 on 1 and 39 DF,  p-value: 0.155

As you can see the p-value agrees with the dimdesc() output (0.155), however the estimate for OlympicG is (0.879) which is two times more than what dimdesc() function reported, why is that? Is there a statistical explanation to this or is it a bug in the function?

Below is an excerpt from the book about FactoMineR using the same dataset on these estimates with some explanation:

Book excerpt on FactoMineR

On page 40 of "Exploratory Multivariate Analysis by Example Using R" by François Husson, we read the following:

enter image description here

Note

FactoMineR version:2.6

R version 4.2.1 (2022-06-23) -- "Funny-Looking Kid"

$\endgroup$

1 Answer 1

0
$\begingroup$

According to the author of the FactoMineR package, this has something to do with how contrasts are set when using ANOVA test. According to the book and the given dataset, the two categories Olympic Games and Decastar the Competition grouping variable need to be contrasted. This can be achieved in R using the contrasts() function.

contrasts(decathlon$Competition) <- c(-1, 1) # sum will be zero
decathlon$Competition

 [1] Decastar Decastar Decastar Decastar Decastar Decastar Decastar Decastar
 [9] Decastar Decastar Decastar Decastar Decastar OlympicG OlympicG OlympicG
[17] OlympicG OlympicG OlympicG OlympicG OlympicG OlympicG OlympicG OlympicG
[25] OlympicG OlympicG OlympicG OlympicG OlympicG OlympicG OlympicG OlympicG
[33] OlympicG OlympicG OlympicG OlympicG OlympicG OlympicG OlympicG OlympicG
[41] OlympicG
attr(,"contrasts")
         [,1]
Decastar   -1
OlympicG    1
Levels: Decastar OlympicG

Now we do ANOVA test again with the contrasts in place:

resAOV <- aov(PC1 ~ Competition, data = decathlon, na.action = na.exclude)

summary.lm(resAOV)
Call:
aov(formula = PC1 ~ Competition, data = decathlon, na.action = na.exclude)

Residuals:
   Min     1Q Median     3Q    Max 
-3.379 -0.961 -0.009  0.957  4.341 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)
(Intercept)    -0.161      0.303   -0.53     0.60
Competition1    0.439      0.303    1.45     0.16

Residual standard error: 1.81 on 39 degrees of freedom
Multiple R-squared:  0.0511,    Adjusted R-squared:  0.0268 
F-statistic:  2.1 on 1 and 39 DF,  p-value: 0.155

Competition1 is the category OlympicG and its estimate now matches the book and the output from dimdesc() function.

$\endgroup$

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.