Using CSV file for HCPC analysis

9 views
Skip to first unread message

Mahmood Naderan

unread,
Feb 4, 2021, 8:55:50 AMFeb 4
to factomin...@googlegroups.com
Hi,
I am new to factominer and have read the HCPC example [1]. My question
is how can I feed a csv file containing my data? My data is a 2D array
of numbers where each column is a string (variables) and each row
starts with a string (observations). So,
data[:0] is the observation list
and
data[0:] is the variable list.

[1] http://factominer.free.fr/factomethods/hierarchical-clustering-on-principal-components.html


Regards,
Mahmood

Mahmood Naderan

unread,
Feb 4, 2021, 9:18:10 AMFeb 4
to FactoMineR users
As a follow up, I have this test file

,V1,V2,V3,V4
P1,73.6,0.7,74.6,3.1
P2,75.2,0.7,75.8,2.8
P3,6.5,0.0,7.3,2.5
P4,41.4,0.3,39.2,8.9
P4,5.4,0.1,18.2,1.1
P5,18.8,0.3,30.3,7.3

But, when I run the following commands, the HCPC gives me an error

> mydata <- read.csv(file = 'test.csv', header = TRUE)
> head(mydata)
   X   V1  V2   V3  V4
1 P1 73.6 0.7 74.6 3.1
2 P2 75.2 0.7 75.8 2.8
3 P3  6.5 0.0  7.3 2.5
4 P4 41.4 0.3 39.2 8.9
5 P4  5.4 0.1 18.2 1.1
6 P5 18.8 0.3 30.3 7.3
> library(FactoMineR)
> res.mca = MCA(mydata, ncp=2, quanti.sup=4, quali.sup=c(1:6), graph=FALSE)
Error in which(unlist(lapply(listModa, is.numeric))) :
  argument to 'which' is not logical

I don't know if the quanti,sup and quali.sup are correct or there is a problem with the CSV file which I have/haven't to read the headers.

Any thought?

Mahmood Naderan

unread,
Feb 4, 2021, 9:57:25 AMFeb 4
to Karima TOUATI, factomin...@googlegroups.com
That X is because the mydata[0,0] has no label.
Please see the picture showing mydata https://pasteboard.co/JMObSMi.png

As I said the array is put in a data frame where the left column shows the observations and the top row shows the variable list.

Also, please see the following error:

> res.mca = MCA(mydata, ncp=2, quali.sup=1, graph=FALSE)

Error in which(unlist(lapply(listModa, is.numeric))) :
  argument to 'which' is not logical


Regards,
Mahmood





On Thu, Feb 4, 2021 at 3:44 PM Karima TOUATI <karimat...@gmail.com> wrote:

You have only the variables :  X   V1  V2   V3  V4 in your data ?
If it is the case you should correct as following :
 res.mca = MCA(mydata, ncp=2, quali.sup=1, graph=FALSE)
I don't know if X is the list of individuals or another variable.

Best regards,
Karima TOUATI

Statistics & Data Analysis Engineer
Ecole Supérieure de la Statistique et de l'Analyse de l'Information - ESSAI
Phone : (+216) 20 737 837
LinkedIn : Linkedin
GitHub :  Github
Twitter : Twitter




--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes "FactoMineR users".
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse factominer-use...@googlegroups.com.
Cette discussion peut être lue sur le Web à l'adresse https://groups.google.com/d/msgid/factominer-users/cd180379-ca3f-4988-a31e-6321d79d2be7n%40googlegroups.com.

Mailtrack Sender notified by
Mailtrack 04/02/21, 15:42:43

J.C. Deroubaix

unread,
Feb 4, 2021, 9:58:55 AMFeb 4
to factomin...@googlegroups.com
As I see your data, I think that MCA is not the good option, the good one may be CA (if the numbers are counts
) or PCA if they are réal numbers. 

J.C.Deroubaix



Mahmood Naderan

unread,
Feb 4, 2021, 10:39:04 AMFeb 4
to factomin...@googlegroups.com
Well that is a test file. The original file contains 39 columns and 69
rows and the numbers are floating points.
Why did you say that MCA is not good? Only because of the small size?

Regards,
Mahmood
> Vous recevez ce message, car vous êtes abonné à un sujet dans le groupe Google Groupes "FactoMineR users".
> Pour vous désabonner de ce sujet, visitez le site https://groups.google.com/d/topic/factominer-users/7I9tV7_ZuHo/unsubscribe.
> Pour vous désabonner de ce groupe et de tous ses sujets, envoyez un e-mail à l'adresse factominer-use...@googlegroups.com.
> Cette discussion peut être lue sur le Web à l'adresse https://groups.google.com/d/msgid/factominer-users/82116E1E-B03F-40D7-8414-63A5416B7625%40skynet.be.

J.C. Deroubaix

unread,
Feb 4, 2021, 10:51:17 AMFeb 4
to factomin...@googlegroups.com
MCA : is a analysis of a set of categorical variables. the colomns must be the catégories.

You have 4 réal variables, you must then use PCA and HCPC.

Best regards,

Jean-Claude
> Cette discussion peut être lue sur le Web à l'adresse https://groups.google.com/d/msgid/factominer-users/CADa2P2XvhSb6L9Hwvoe3GDVCD0%3DNFLRAv3v9YBsKtXdF4RnLLA%40mail.gmail.com.

Mahmood Naderan

unread,
Feb 4, 2021, 10:54:39 AMFeb 4
to factomin...@googlegroups.com
Yes. Based on the example [1] I have to first run MCA and then HCPC.
Isn't that right?
But as I said, I get an error at the MCA step.
> Cette discussion peut être lue sur le Web à l'adresse https://groups.google.com/d/msgid/factominer-users/40862B3B-5CBA-4768-BB26-BDEECE26DC7A%40skynet.be.

J.C. Deroubaix

unread,
Feb 4, 2021, 1:14:39 PMFeb 4
to factomin...@googlegroups.com
No, you are wrong.

As it is said in the exemple : you have to use principal components, in your case it is PCA (Principal components analysis) then HCPC. Try it.
> Cette discussion peut être lue sur le Web à l'adresse https://groups.google.com/d/msgid/factominer-users/CADa2P2VMZpR57EZ18fVne6GpA6e6F9WeO496VQRAzYxmivET8w%40mail.gmail.com.

Mahmood Naderan

unread,
Feb 4, 2021, 3:54:42 PMFeb 4
to factomin...@googlegroups.com
OK. I read that and will try it.
Thanks.


Regards,
Mahmood
Reply all
Reply to author
Forward
0 new messages