ericgoolsby / Rphylopars

Phylogenetic Comparative Tools for Missing Data and Within-Species Variation
28 stars 11 forks source link

R Session Aborted - R encountered a fatal error. #47

Closed rianbreak closed 2 years ago

rianbreak commented 2 years ago

I have a data set of continuous trait characters for multiple species with intra-specific variation, i.e. multiple observations for one species. And I'm trying to perform an ancestral state reconstruction on this data set. But every time I try to run phylopars(), R aborts the session, without displaying an error message. I have already checked the reasons, this error was caused for others, i.e. all my names in the tree and the "species" column of the data set are identical and none are missing in either. This is the code I use:

tree <- read.tree(text = "(((((((((myrmasc, (nemopterinae, crocinae)), 
                  nymphidae), psychopsidae), ithonidae), hemerobiidae), 
                  (berothidae, mantispidae)), chrysopidae), dilaridae), 
                  (osmylidae, (sisyridae, nevrorthidae)));")
tree <- multi2di(tree)
tree <- compute.brlen(tree, method = "Grafen", power = 1)
is.binary(tree)
is.rooted(tree)
data <- data.frame(test_data[, c(6, 8:10)])
colnames(data)[which(names(data) == "Group_tree")] <- "species"
asr <- phylopars(trait_data = data, tree = tree, 
                 model = "BM", phylo_correlated = TRUE, pheno_error = TRUE, 
                 pheno_correlated = TRUE)

I have tried reducing/changing the number of observations per species, as well as the number of continuous characters used, as well the resolution of the tree and the branch lengths, but nothing helped.

As I don't receive any error messages, I also cannot work on a solution...

ericgoolsby commented 2 years ago

Apologies for the delay. The crashing R is something that should be avoided for sure. One issue could be the hard return when you create the tree from text. For me, your tree code causes one of the species to begin with \n:

> tree$tip.label
 [1] "myrmasc"      "nemopterinae" "crocinae"     "\nnymphidae"  "psychopsidae" "ithonidae"    "hemerobiidae" "berothidae"   "mantispidae" 
[10] "chrysopidae"  "dilaridae"    "osmylidae"    "sisyridae"    "nevrorthidae"

However I didn't have any issues with crashing.

Does the following code return TRUE? If not, that could be an issue.

all(data$species %in% tree$tip.label)

Another thing you might try: if you run the following code using your tree, do you get an error?

sim <- simtraits(tree=tree)
phylopars(trait_data = sim$trait_data,tree = tree)

If that works, then it suggests there's an issue with your trait values. If you have missing data, make sure it's coded as NA. Additionally, make sure the trait columns are numeric, and not some other datatype.

Beyond that, I'm not sure what it could be, but perhaps it could be reproduced if you included the test data you're working with.

rianbreak commented 2 years ago

No worries. So upon noticing the "/n" in your code, which was not visible in mine, I re-wrode the whole tree by hand in R and now it works. So, like the other times, a difference between the tree tip labels and the entries in the species column of the data seems to cause the crashes. Thanks for the help!