diff --git a/NAMESPACE b/NAMESPACE index b33a6ec79d5ef141164da7aa97e9cafd78d24954..0f83aa016788f2d0a0b5756222042acc216645ab 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,9 +1,12 @@ # Generated by roxygen2: do not edit by hand +export(fisher_mix) export(treediff) importFrom(dplyr,"%>%") importFrom(dplyr,group_by) importFrom(dplyr,summarise) importFrom(limma,squeezeVar) +importFrom(reshape2,colsplit) importFrom(stats,cophenetic) importFrom(stats,pt) +importFrom(stats,rf) diff --git a/R/treediff.R b/R/treediff.R index 7fa14abd65b42f93552a795957fcd38d3fa5f2bb..2532a91f90f4d2d4043d2abb99eabdbd5f521a98 100644 --- a/R/treediff.R +++ b/R/treediff.R @@ -17,7 +17,8 @@ #' @param replicates A numeric vector of length 2 with the number of replicates #' for each condition. #' -#' @return An object of class \code{treeTest} with the following entries: \itemize{ +#' @return An object of class \code{treeTest} with the following entries: +#' \itemize{ #' \item{p.value}{ the p-value for the treediff test.} #' \item{statistic}{ the value of the Student's statistic of each leaf pair of #' the tree test.} @@ -29,10 +30,11 @@ #' conditions.} #' } #' -#' @author Pierre Neuvial \email{pierre.neuvial@math.univ-toulouse.fr}\cr -#' Nathanaël Randriamihamison\cr +#' @author Gwendaelle Cardenac\cr #' Marie Chavent \email{marie.chavent@u-bordeaux.fr}\cr #' Sylvain Foissac \email{sylvain.foissac@inrae.fr}\cr +#' Pierre Neuvial \email{pierre.neuvial@math.univ-toulouse.fr}\cr +#' Nathanaël Randriamihamison\cr #' Nathalie Vialaneix \email{nathalie.vialaneix@inrae.fr} #' #' @references Neuvial Pierre, Randriamihamison Nathanaël, Chavent Marie, @@ -52,11 +54,10 @@ #' #' #' @examples +#' leaves <- c(100, 120, 50, 80) #' -#' leaves <- c(100,120,50,80) -#' -#' trees <- sapply(leaves, FUN = function(l){ -#' base_data <- matrix(rnorm(2000), nrow = l, ncol = 200) +#' trees <- sapply(leaves, FUN = function(leaf) { +#' base_data <- matrix(rnorm(2000), nrow = leaf, ncol = 200) #' #' ## generates two sets of trees with 4 clusters with 100, 120, 50 and 80 #' ## leaves respectively @@ -79,22 +80,22 @@ #' return(list("trees1" = trees1, "trees2" = trees2)) #' }) #' -#' trees1 <- unlist(trees[1,], recursive = FALSE) -#' trees2 <- unlist(trees[2,], recursive = FALSE) -#' replicates = c(4, 6) +#' trees1 <- unlist(trees[1, ], recursive = FALSE) +#' trees2 <- unlist(trees[2, ], recursive = FALSE) +#' replicates <- c(4, 6) #' #' tree_pvals <- treediff(trees1, trees2, replicates) #' ## 4 p-values, one for each cluster #' tree_pvals$p.value -treediff <- function(trees1, trees2, replicates){ +treediff <- function(trees1, trees2, replicates) { # Check if `replicates` is numeric vector - if (inherits(replicates, "numeric") != TRUE){ + if (inherits(replicates, "numeric") != TRUE) { stop("`replicates` is not a numeric vector") } # Check if the length of replicates is 2 - if (length(replicates) != 2){ + if (length(replicates) != 2) { stop("`replicates` must be a vector of length 2.") } @@ -111,7 +112,7 @@ treediff <- function(trees1, trees2, replicates){ tree_order2 <- lapply(trees2, "[[", "order") leaves2 <- sapply(tree_order2, length) - if (!identical(unique(leaves1), unique(leaves2))){ + if (!identical(unique(leaves1), unique(leaves2))) { stop("the number of leaves in one or more clusters is different between ", "the two sets of trees.") } @@ -230,7 +231,7 @@ compute_pvalue <- function(average_coph, squeezed_var, replicates) { cluster <- average_coph$cluster # Calculate the numerator for the t-statistic - numerator <- Reduce("-", average_coph[,-3]) + numerator <- Reduce("-", average_coph[, -3]) # Store replicates values for each group n1 <- replicates[1] diff --git a/man/treediff.Rd b/man/treediff.Rd index cdaf4664bb699470ba923458daa1a9fd93853902..4c69c8a1d6045c497c9b6b2a89d60d392af7f387 100644 --- a/man/treediff.Rd +++ b/man/treediff.Rd @@ -21,7 +21,8 @@ different from that of \code{trees1}.} for each condition.} } \value{ -An object of class \code{htest} with the following entries: \itemize{ +An object of class \code{treeTest} with the following entries: +\itemize{ \item{p.value}{ the p-value for the treediff test.} \item{statistic}{ the value of the Student's statistic of each leaf pair of the tree test.} @@ -42,11 +43,10 @@ method. The p-values are obtained by the treediff method, as described in (Neuvial \emph{et al.}, 2023). } \examples{ +leaves <- c(100, 120, 50, 80) -leaves <- c(100,120,50,80) - -trees <- sapply(leaves, FUN = function(l){ - base_data <- matrix(rnorm(2000), nrow = l, ncol = 200) +trees <- sapply(leaves, FUN = function(leaf) { + base_data <- matrix(rnorm(2000), nrow = leaf, ncol = 200) ## generates two sets of trees with 4 clusters with 100, 120, 50 and 80 ## leaves respectively @@ -69,9 +69,9 @@ trees <- sapply(leaves, FUN = function(l){ return(list("trees1" = trees1, "trees2" = trees2)) }) -trees1 <- unlist(trees[1,], recursive = FALSE) -trees2 <- unlist(trees[2,], recursive = FALSE) -replicates = c(4, 6) +trees1 <- unlist(trees[1, ], recursive = FALSE) +trees2 <- unlist(trees[2, ], recursive = FALSE) +replicates <- c(4, 6) tree_pvals <- treediff(trees1, trees2, replicates) ## 4 p-values, one for each cluster @@ -84,9 +84,10 @@ structure between families of trees. \emph{Preprint submitted for publication}. } \author{ -Pierre Neuvial \email{pierre.neuvial@math.univ-toulouse.fr}\cr -Nathanaël Randriamihamison\cr +Gwendaelle Cardenac\cr Marie Chavent \email{marie.chavent@u-bordeaux.fr}\cr Sylvain Foissac \email{sylvain.foissac@inrae.fr}\cr +Pierre Neuvial \email{pierre.neuvial@math.univ-toulouse.fr}\cr +Nathanaël Randriamihamison\cr Nathalie Vialaneix \email{nathalie.vialaneix@inrae.fr} }