diff --git a/R/treediff.R b/R/treediff.R index c0e08ae99f3df9db221016c373d15b7e70c5283e..e128bd307af867461faa6bfeeb173a732310819e 100644 --- a/R/treediff.R +++ b/R/treediff.R @@ -48,12 +48,12 @@ treediff <- function(trees1, trees2, replicats){ stop("The number of clusters is different between conditions or `replicats' is uncorrect") } - # Extract the number of pair of the trees - tree_order <- lapply(trees1, "[[", "order") - leaves <- sapply(tree_order, length) - - # Get unique values of the number of leaves - leaves <- unique(leaves) + # # Extract the number of pair of the trees + # tree_order <- lapply(trees1, "[[", "order") + # leaves <- sapply(tree_order, length) + # + # # Get unique values of the number of leaves + # leaves <- unique(leaves) # Merge trees from both conditions trees <- c(trees1, trees2) @@ -66,14 +66,15 @@ treediff <- function(trees1, trees2, replicats){ adist <- as.matrix(adist) return(adist[upper.tri(adist)]) }) - # Fill the cophenetic vector with NA if the number of leaves is different from the max. - if (length(leaves) != 1){ - len_max <- choose(max(leaves), 2) - coph_vect <- sapply(coph_vect, FUN = function(col) { - c(col, rep(NA, len_max - length(col))) - }) - } + # # Fill the cophenetic vector with NA if the number of leaves is different from the max. + # if (length(leaves) != 1){ + # len_max <- choose(max(leaves), 2) + # + # coph_vect <- sapply(coph_vect, FUN = function(col) { + # c(col, rep(NA, len_max - length(col))) + # }) + # } # Compute squeeze factor outs <- compute_squeeze(coph_vect, replicats) @@ -101,6 +102,13 @@ treediff <- function(trees1, trees2, replicats){ compute_squeeze <- function(dist_coph, replicats){ + if (class(dist_coph) == "list"){ + max_pr <- as.numeric(max(summary(dist_coph)[,1])) + dist_coph <- sapply(dist_coph, FUN = function(col) { + c(col, rep(NA, max_pr - length(col))) + }) + } + # Calculate number of clusters nb_cluster <- ncol(dist_coph)/sum(replicats) @@ -172,7 +180,7 @@ compute_pvalue <- function(average_coph, squeezed_var, replicats){ # Calculate the t-statistic statistics <- numerator / sqrt(denominator) - # Extract the degrees of freedom for the t-distribution + # Extract the degrees of freedom d0 <- squeezed_var$df.prior # Calculate the p-value