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

Possible extension of factoextra to include ExPosition #23

Open
kassambara opened this issue Nov 20, 2016 · 4 comments
Open

Possible extension of factoextra to include ExPosition #23

kassambara opened this issue Nov 20, 2016 · 4 comments

Comments

@kassambara
Copy link
Owner

From private e-mail:

CA, MCA, PCA, MDS (ExPosition, InPosition for inferences)
Discriminant Correspondence Analysis (DiCA), PLSC, (TExPosition, TInPosition for inferences), barycentrique discriminant analysis
MFA, STATIS and variants (MExPosition)

@kassambara
Copy link
Owner Author

kassambara commented Dec 31, 2016

Now, factoextra R functions have been simplified to make easy the extension of factoextra to other packages.

If you want to extend the existing factoextra functions to other packages, you need to update only the following functions :

  1. .get_facto_class()
  2. get_eig()
  3. one of these functions depending on the type of the analysis: get_pca(), get_ca(), get_mca(), get_famd(), get_mfa() or get_hmfa()

Additionally,

  • for CA, you should also update the function .get_ca_mass() in the utilities.R file
  • for PCA, you should also update the function .get_scale_unit()

If you want to add a new functionality, you need to update the functions below:

  • update get_eig()
  • Update .get_facto_class()
  • Update facto_summarize()
  • update print.factoextra

For example, to extend the factoextra package to handle the results of the functions epCA(), epMCA() and epMCA() [in the ExPosition Package], we used the following R scipt:

# Added in .get_facto_class()
#%%%%%%%%%%%%%%%%
if (inherits(X, "expoOutput")){
   if (inherits(X$ExPosition.Data,'epCA')) facto_class="CA"
   else if (inherits(X$ExPosition.Data,'epPCA')) facto_class="PCA"
   else if (inherits(X$ExPosition.Data,'epMCA')) facto_class="MCA"
  }

# epCA: Correspondence Analysis
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
library(ExPosition)
data(authors)
res.ca <- epCA(authors$ca$data, graph = FALSE)
res <- res.ca$ExPosition.Data
# eigenvalues (used in get_eig())
eig <- res$eigs
# Results for rows (used in get_ca_row())
coord <- res$fi
inertia <- res$di*res$M
cos2 <- res$ri
contrib <- res$ci*100
mass <- res$M # .get_ca_mass() 
# Results for columns (used in get_ca_col())
coord <- res$fj
inertia <- res$dj*res$W
cos2 <- res$rj
contrib <- res$cj*100
mass <- res$w # .get_ca_mass()

# epMCA: Multiple Correspondence Analysis
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
library(ExPosition)
data(mca.wine)
res.mca <- epMCA(mca.wine$data, graph = FALSE)
res <- res.mca$ExPosition.Data
# eigenvalues (used in get_eig())
eig <- res$eigs
# Results for rows/individuals (used in get_mca_ind())
coord <- res$fi
inertia <- res$di*res$M
cos2 <- res$ri
contrib <- res$ci*100
mass <- res$M # .get_ca_mass() 
# Results for columns/variables (used in get_mca_var())
coord <- res$fj
inertia <- res$dj*res$W
cos2 <- res$rj
contrib <- res$cj*100
mass <- res$w # .get_ca_mass()

#epPCA
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%
library(ExPosition)
res.pca <- epPCA(iris[, -5], graph=FALSE)
res <- res.pca$ExPosition.Data
# Eigenvalues (used in get_eig())
res$eigs # Valeurs très élévée par rapport à FactoMineR::PCA(iris[,-5], graph=FALSE)$eig
# Results for individuals (used in get_pca_ind())
ind.coord <- res$fi
ind.contrib <- res$ci*100
ind.cos2 <- res$ri
# Results for variables (used in get_pca_var())
var.coord <- var.cor <- cor(res$X, res$fi) # cor(t(data_matrix), factor_scores)
var.contrib <- res$cj*100
var.cos2 <- res$rj

kassambara added a commit that referenced this issue Dec 31, 2016
@kassambara
Copy link
Owner Author

Support for ExPosition::epCA() added:

library(ExPosition)
data(authors)
res.ca <- epCA(authors$ca$data)

# Visualize
library(factoextra)
fviz_ca_biplot(res.ca)

ca-biplot

kassambara added a commit that referenced this issue Jan 1, 2017
@kassambara
Copy link
Owner Author

Support for ExPosition::epPCA() added:

library(ExPosition)
res.pca <- epPCA(iris[, -5], graph=FALSE)

library(factoextra)
fviz_pca_ind(res.pca,
             label = "none", # hide individual labels
             habillage = iris$Species, # color by groups
             addEllipses = TRUE # Concentration ellipses
)

rplot08

@kassambara
Copy link
Owner Author

Support for ExPosition::epMCA() added:

# Compute MCA
library(ExPosition)
data(mca.wine)
res.mca <- epMCA(mca.wine$data, graph = FALSE)
``

- Load factoextra for visualization

```r
library(factoextra)
  • Visualize rows/individuals, use repel = TRUE to avoid labels overlapping
library(factoextra)
fviz_mca_ind(res.mca, repel = TRUE)

rplot09

  • Visualize columns/variables, use repel = TRUE to avoid labels overlapping
fviz_mca_var(res.mca, repel = TRUE )

rplot10

  • Biplot of individuals and variables
fviz_mca_biplot(res.mca, repel = TRUE)

rplot11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant