Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object of class dist as an input to fviz_nbclust #15

Closed
Nowosad opened this issue Sep 16, 2016 · 2 comments
Closed

Object of class dist as an input to fviz_nbclust #15

Nowosad opened this issue Sep 16, 2016 · 2 comments

Comments

@Nowosad
Copy link

Nowosad commented Sep 16, 2016

Hi!

I've tried to use fviz_nbclust function. Based on the help page, it should takes an object x (matrixor data.frame). However, it's also possible to put there dist object and to get different results:

library('cluster')
library('factoextra')
options(scipen=9)

df <- USArrests
dist_df <- dist(USArrests)

fviz_nbclust(x=df, FUNcluster=pam, method='wss')
fviz_nbclust(x=dist_df, FUNcluster=pam, method='wss')

I've checked the source code and found out that inside the function fviz_nbclust every x object is transformed to dist object. Maybe the better way is to transform only matrixand data.frameobject and not transforming dist. Alternatively (but probably not so good) is to forbid dist object as an input.

What do you think?

@kassambara
Copy link
Owner

Hi @Nowosad ,

Thank you very much for reporting that.

yes, every x is transformed to dist for computing 'wss' but we need also the original matrix value to compute FUNcluster, for example "pam".

I think that the best option is to accept only the original matrix value as an input. I changed the function accordingly.

Best regards,
A.

@Nowosad
Copy link
Author

Nowosad commented Sep 17, 2016

Hi @kassambara,
thanks for the answer. Yes, you probably right about the best option.

Best regards,
J.

PS Correct me if I'm wrong - pam accept dist object also (without having an original matrix). On the other hand clara needs to have an original matrix...

@Nowosad Nowosad closed this as completed Sep 17, 2016
@Nowosad Nowosad reopened this Sep 17, 2016
@Nowosad Nowosad closed this as completed Mar 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants