Skip to content

Commit

Permalink
add force_jaccard_binary param in cal_betadiv of microtable
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiLiubio committed Jan 24, 2025
1 parent c3e684b commit 5723a43
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
14 changes: 10 additions & 4 deletions R/microtable.R
Original file line number Diff line number Diff line change
Expand Up @@ -762,16 +762,18 @@ microtable <- R6Class(classname = "microtable",
#' @param method default NULL; a character vector with one or more elements; \code{c("bray", "jaccard")} is used when \code{method = NULL};
#' See the \code{method} parameter in \code{vegdist} function for more available options, such as 'aitchison' and 'robust.aitchison'.
#' @param unifrac default FALSE; whether UniFrac indexes (weighted and unweighted) are calculated. Phylogenetic tree is necessary when \code{unifrac = TRUE}.
#' @param binary default FALSE; Whether convert abundance to binary data (presence/absence) when \code{method} is not "jaccard".
#' TRUE is used for "jaccard" automatically.
#' @param binary default FALSE; Whether convert abundance to binary data (presence/absence).
#' @param force_jaccard_binary default TRUE; Whether forcibly convert abundance to binary data (presence/absence) when \code{method = "jaccard"}.
#' The reason for this setting is that the Jaccard metric is commonly used for binary data.
#' If \code{force_jaccard_binary = FALSE} is set, the conversion will not be enforced, but will instead be based on the setting of the \code{binary} parameter.
#' @param ... parameters passed to \code{vegdist} function of vegan package.
#' @return beta_diversity list stored in the object.
#' @examples
#' \donttest{
#' m1$cal_betadiv(unifrac = FALSE)
#' class(m1$beta_diversity)
#' }
cal_betadiv = function(method = NULL, unifrac = FALSE, binary = FALSE, ...){
cal_betadiv = function(method = NULL, unifrac = FALSE, binary = FALSE, force_jaccard_binary = TRUE, ...){
res <- list()
eco_table <- t(self$otu_table)
sample_table <- self$sample_table
Expand All @@ -784,7 +786,11 @@ microtable <- R6Class(classname = "microtable",
for(i in method){
i <- match.arg(i, vegdist_methods)
if(i == "jaccard"){
binary_use <- TRUE
if(force_jaccard_binary){
binary_use <- TRUE
}else{
binary_use <- binary
}
}else{
binary_use <- binary
}
Expand Down
2 changes: 1 addition & 1 deletion R/trans_beta.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ trans_beta <- R6Class(classname = "trans_beta",
#' For the methods details, please refer to the papers <doi:10.1111/j.1574-6941.2007.00375.x> (for PCoA, NMDS, PCA and DCA) and
#' <doi:10.1186/s12859-019-3310-7> (for PLS-DA or OPLS-DA).
#' @param ncomp default 3; dimensions shown in the results (except method "NMDS").
#' @param trans default FALSE; whether species abundance will be square transformed; only available when \code{method} is "PCA" or "DCA".
#' @param trans default FALSE; whether species abundance will be square root transformed; only available when \code{method} is "PCA" or "DCA".
#' @param scale_species default FALSE; whether species loading in PCA or DCA is scaled.
#' @param scale_species_ratio default 0.8; the ratio to scale up the loading; multiply by the maximum distance between samples and origin.
#' Only available when \code{scale_species = TURE}.
Expand Down
15 changes: 12 additions & 3 deletions man/microtable.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/trans_beta.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5723a43

Please sign in to comment.