From eb6efe254a830a60c23e281617d1824ce18b9f06 Mon Sep 17 00:00:00 2001 From: nfrerebeau Date: Fri, 17 Nov 2023 17:36:54 +0100 Subject: [PATCH] Reexport pca() from dimensio --- NAMESPACE | 2 ++ R/AllGenerics.R | 2 +- R/pca.R | 4 ++-- R/reexport.R | 4 ++++ man/pca.Rd | 8 ++++---- man/reexports.Rd | 3 +++ pkgdown/_pkgdown.yml | 6 +++--- vignettes/nexus.Rmd | 18 ++++++++++++++---- 8 files changed, 33 insertions(+), 14 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index af30345..105f423 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -12,6 +12,7 @@ S3method(mean,CompositionMatrix) S3method(plot,CompositionMatrix) S3method(plot,LogRatio) S3method(plot,OutlierIndex) +export(pca) export(remove_NA) export(remove_zero) export(replace_NA) @@ -67,6 +68,7 @@ importFrom(arkhe,remove_NA) importFrom(arkhe,remove_zero) importFrom(arkhe,replace_NA) importFrom(arkhe,replace_zero) +importFrom(dimensio,pca) importFrom(grDevices,hcl.colors) importFrom(methods,"as<-") importFrom(methods,"slot<-") diff --git a/R/AllGenerics.R b/R/AllGenerics.R index 58ed699..b5780ab 100644 --- a/R/AllGenerics.R +++ b/R/AllGenerics.R @@ -928,7 +928,7 @@ setGeneric( #' @author N. Frerebeau #' @docType methods #' @family multivariate analysis -#' @name pca +#' @name pca_coda #' @rdname pca NULL diff --git a/R/pca.R b/R/pca.R index d0806a0..54a06b0 100644 --- a/R/pca.R +++ b/R/pca.R @@ -8,7 +8,7 @@ NULL setMethod( f = "pca", signature = c("CompositionMatrix"), - definition = function(object, center = TRUE, scale = TRUE, rank = NULL, + definition = function(object, center = TRUE, scale = FALSE, rank = NULL, sup_row = NULL, sup_col = NULL, weight_row = NULL, weight_col = NULL) { stop("You should not do that! Transform your data first.", call. = FALSE) @@ -21,7 +21,7 @@ setMethod( setMethod( f = "pca", signature = c("LogRatio"), - definition = function(object, center = TRUE, scale = TRUE, rank = NULL, + definition = function(object, center = TRUE, scale = FALSE, rank = NULL, sup_row = NULL, sup_col = NULL, weight_row = NULL, weight_col = NULL) { z <- methods::callNextMethod() diff --git a/R/reexport.R b/R/reexport.R index 606f61b..86d3c3f 100644 --- a/R/reexport.R +++ b/R/reexport.R @@ -15,3 +15,7 @@ arkhe::remove_NA #' @importFrom arkhe remove_zero #' @export arkhe::remove_zero + +#' @importFrom dimensio pca +#' @export +dimensio::pca diff --git a/man/pca.Rd b/man/pca.Rd index 436e33f..ebe9012 100644 --- a/man/pca.Rd +++ b/man/pca.Rd @@ -1,8 +1,8 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/AllGenerics.R, R/pca.R \docType{methods} -\name{pca} -\alias{pca} +\name{pca_coda} +\alias{pca_coda} \alias{pca,CompositionMatrix-method} \alias{pca,LogRatio-method} \title{Principal Components Analysis} @@ -10,7 +10,7 @@ \S4method{pca}{CompositionMatrix}( object, center = TRUE, - scale = TRUE, + scale = FALSE, rank = NULL, sup_row = NULL, sup_col = NULL, @@ -21,7 +21,7 @@ \S4method{pca}{LogRatio}( object, center = TRUE, - scale = TRUE, + scale = FALSE, rank = NULL, sup_row = NULL, sup_col = NULL, diff --git a/man/reexports.Rd b/man/reexports.Rd index 385b826..62bc33c 100644 --- a/man/reexports.Rd +++ b/man/reexports.Rd @@ -7,6 +7,7 @@ \alias{replace_zero} \alias{remove_NA} \alias{remove_zero} +\alias{pca} \title{Objects exported from other packages} \keyword{internal} \description{ @@ -15,5 +16,7 @@ below to see their documentation. \describe{ \item{arkhe}{\code{\link[arkhe:missing]{remove_NA}}, \code{\link[arkhe:zero]{remove_zero}}, \code{\link[arkhe:missing]{replace_NA}}, \code{\link[arkhe:zero]{replace_zero}}} + + \item{dimensio}{\code{\link[dimensio]{pca}}} }} diff --git a/pkgdown/_pkgdown.yml b/pkgdown/_pkgdown.yml index 41db16f..d526d2b 100644 --- a/pkgdown/_pkgdown.yml +++ b/pkgdown/_pkgdown.yml @@ -22,12 +22,12 @@ reference: - title: Missing Values contents: - has_concept("imputation methods") -- title: Multivariate Analysis - contents: - - has_concept("multivariate analysis") - title: Outlier Detection contents: - has_concept("outlier detection methods") +- title: Multivariate Analysis + contents: + - has_concept("multivariate analysis") - title: Getters and Setters contents: - has_concept("mutators") diff --git a/vignettes/nexus.Rmd b/vignettes/nexus.Rmd index f7acc6a..c21b54f 100644 --- a/vignettes/nexus.Rmd +++ b/vignettes/nexus.Rmd @@ -184,12 +184,12 @@ barplot(coda, order = "Ca") ## Principle Component Analysis ```{r ceramics-pca, fig.width=7, fig.height=7, out.width='50%', fig.show='hold'} -library(dimensio) - ## CLR clr <- transform_clr(coda) ## PCA +library(dimensio) + clr_pca <- pca(clr, scale = FALSE) viz_individuals(clr_pca, highlight = get_groups(coda), pch = 16, @@ -200,15 +200,25 @@ viz_variables(clr_pca) ## MANOVA ```{r ceramics-manova} -fit <- manova(transform_ilr(coda) ~ get_groups(coda)) +## ILR +ilr <- transform_ilr(coda) + +## MANOVA +fit <- manova(ilr ~ get_groups(ilr)) summary(fit) ``` The MANOVA results suggest that there are statistically significant differences between groups. +## Discriminant Analysis + ```{r ceramics-lda, fig.width=7, fig.height=7, out.width='100%'} -discr <- MASS::lda(transform_ilr(coda), grouping = get_groups(coda)) +## LDA +discr <- MASS::lda(ilr, grouping = get_groups(ilr)) plot(discr) + +## Back transform results +transform_inverse(discr$means, origin = ilr) ``` # References