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

Error in resolveTreeChar() when orderedChar = TRUE #45

Open
zenalapp opened this issue Mar 26, 2025 · 0 comments
Open

Error in resolveTreeChar() when orderedChar = TRUE #45

zenalapp opened this issue Mar 26, 2025 · 0 comments

Comments

@zenalapp
Copy link

I've been using the resolveTreeChar() function with orderedChar = TRUE and stateBias = 'primitive'. Most of the time it works perfectly but every once in a while I get an error. Here's the error from the example below:

Error in testEdgeMat(tree) :
  Some elements of edge are numbered greater than 9
calculated from Nnode+length(tree$tip.label)
Check these: 10

I understand what the error is saying, but I'm having difficulty figuring out how to troubleshoot. I can't find a consistent pattern of when it throws an error and when it doesn't. I'm using this function on many trees, so it would be difficult to manually go through and troubleshoot individual ones to make them work (assuming that's even a good idea).

Do you have any thoughts on how to fix this error?

Here is an example where it throws an error with orderedChar = TRUE, but not orderedChar = FALSE (I haven't found an instance where it throws an error with orderedChar = FALSE, but I also haven't tried that hard). And if you change the tips labeled "74" to "31", then it works for both.

library(paleotree)
 
# example tree that doesn't work for orderedChar = TRUE
example_tree <- structure(list(edge = structure(c(6L, 6L, 6L, 6L, 6L, 1L, 2L, 3L, 4L, 5L), dim = c(5L, 2L)),
                                edge.length = c(0.0019837977, 0.012936646, 0.0265849463, 0.0033293995, 0.0053513114),
                                Nnode = 1L, node.label = "", tip.label = c("74", "458", "807", "74", "262")),
                           class = "phylo", order = "cladewise")
 
example_trait <- factor(example_tree$tip.label, levels = sort(unique(as.numeric(example_tree$tip.label))))
names(example_trait) <- example_tree$tip.label
 
# works with orderedChar = FALSE
example_tree_resolved_unordered <- resolveTreeChar(example_tree, example_trait, orderedChar = FALSE)
# doesn't work with orderedChar = TRUE regardless of stateBias. For my use case, I'd like to use stateBias = 'primitive'.
example_tree_resolved_ordered <- resolveTreeChar(example_tree, example_trait, orderedChar = TRUE)

# changing the "74" tip labels to "31" fixes the problem:
example_tree2 <- example_tree
example_tree2$tip.label[example_tree2$tip.label == "74"] <- "31"

example_trait2 <- factor(example_tree2$tip.label, levels = sort(unique(as.numeric(example_tree2$tip.label))))
names(example_trait2) <- example_tree2$tip.label
example_tree_resolved_unordered2 <- resolveTreeChar(example_tree2, example_trait2, orderedChar = FALSE)
example_tree_resolved_ordered2 <- resolveTreeChar(example_tree2, example_trait2, orderedChar = TRUE)

Session info:

R version 4.4.3 (2025-02-28)
Platform: aarch64-apple-darwin20
Running under: macOS Ventura 13.7.4

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Denver
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] paleotree_3.4.7 ape_5.8-1       devtools_2.4.5  usethis_3.1.0  

loaded via a namespace (and not attached):
 [1] generics_0.1.3          bitops_1.0-9            lattice_0.22-6          digest_0.6.37           magrittr_2.0.3          grid_4.4.3             
 [7] iterators_1.0.14        phytools_2.4-4          maps_3.4.2.1            DEoptim_2.2-8           pkgload_1.4.0           fastmap_1.2.0          
[13] foreach_1.5.2           doParallel_1.0.17       jsonlite_1.9.1          Matrix_1.7-2            pkgbuild_1.4.7          sessioninfo_1.2.3      
[19] optimParallel_1.0-2     urlchecker_1.0.1        combinat_0.0-8          promises_1.3.2          purrr_1.0.4             numDeriv_2016.8-1.1    
[25] codetools_0.2-20        mnormt_2.1.1            cli_3.6.4               shiny_1.10.0            expm_1.0-0              rlang_1.1.5            
[31] scatterplot3d_0.3-44    ellipsis_0.3.2          remotes_2.5.0           cachem_1.1.0            tools_4.4.3             parallel_4.4.3         
[37] memoise_2.0.1           coda_0.19-4.1           httpuv_1.6.15           fastmatch_1.1-6         png_0.1-8               vctrs_0.6.5            
[43] R6_2.6.1                mime_0.13               lifecycle_1.0.4         fs_1.6.5                htmlwidgets_1.6.4       MASS_7.3-64            
[49] miniUI_0.1.1.1          pkgconfig_2.0.3         later_1.4.1             glue_1.8.0              phangorn_2.12.1         profvis_0.4.0          
[55] Rcpp_1.0.14             clusterGeneration_1.3.8 rstudioapi_0.17.1       xtable_1.8-4            htmltools_0.5.8.1       nlme_3.1-167           
[61] igraph_2.1.4            compiler_4.4.3          quadprog_1.5-8          RCurl_1.98-1.17        
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant