plot ancestral states error

431 views
Skip to first unread message

Mario Mairal

unread,
Jul 17, 2014, 12:42:28 PM7/17/14
to bioge...@googlegroups.com
Hello I am new in BioGeoBears,
I am running an analysis with 11 areas and 32 lineages.
I´ve got problems plotting the ancestral states (DIVALIKE). When I try to run #states, this error appears:

Error in marprobs[leftright_nodes_matrix[, 2], ] : 
  subscript out of bounds 

may be a typical beginner's question...
Could anyone help me with this, please? I am thankful for any advice!
Mario 

Nick Matzke

unread,
Jul 17, 2014, 1:20:32 PM7/17/14
to bioge...@googlegroups.com
That's actually a new error, if you're pretty sure you've done all the source() commands and run the example script commands in order, then send me your inputs and I can try to see what the issue is.

Cheers,
Nick



--
You received this message because you are subscribed to the Google Groups "BioGeoBEARS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to biogeobears...@googlegroups.com.
To post to this group, send email to bioge...@googlegroups.com.
Visit this group at http://groups.google.com/group/biogeobears.
To view this discussion on the web visit https://groups.google.com/d/msgid/biogeobears/d0ce81de-535e-4de9-9812-d12d7f824770%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nick Matzke

unread,
Jul 19, 2014, 12:30:30 PM7/19/14
to bioge...@googlegroups.com
Mario sent me his dataset, and I was able to replicate the error, which occurred because the result of the optimx function was coming out as empty after the optimization had finished.  Strangely, though, as soon as I modified the function to print the optimx output to screen, the error went away, and now all the errors/plots work find.  

My suspicion is that this means there is something about optimx, perhaps internal C code, which means that results weren't being transferred to the output quite instantaneously, but having the print statement gives sufficient time for it to catch up.  I have very rarely experience similar weirdness with R interactions with C, FORTRAN, etc.

Anyway, I've posted the update to PhyloWiki.

Mario, or anyone else, if you still get the error, let me know.


PS: I've found that, sometimes, copying/pasting large chunks of code into e.g. Mac Terminal can cause errors, due either to some kind of buffer limit on how much can be pasted in, or some command that is a little bit slow -- e.g. sourcing remote files.  E.g.:

===========

# default here is your home dire> source("http://phylo.wsource(com/local--files/el_v1.R")rs/BioGeoBEARS_univ_mod 

Error in file(filename, "r", encoding = encoding) : 

  cannot open the connection

In addition: Warning message:

In file(filename, "r", encoding = encoding) :

  unable to resolve 'phylo.wsource(com'

===========

...if you see something like this (and sometimes it goes by fast, so scroll up), a command didn't fully paste in, and caused an error, so you have to go back and paste things in chunk-by-chunk.

One alternative is to run your script from the Terminal with e.g.:

R CMD BATCH scriptname.R

Cheers!
Nick

Mario Mairal

unread,
Aug 22, 2014, 6:34:50 AM8/22/14
to bioge...@googlegroups.com
Thank you very much Nick! very useful!

Olympia P.

unread,
Jan 26, 2016, 7:03:17 PM1/26/16
to BioGeoBEARS, mat...@nimbios.org
Hello Nick,

I have also encountered the following error, but while running DEC+J:

Error in marprobs[leftright_nodes_matrix[, 2], ] : 
  subscript out of bounds

In addition to this error message I also received one other:

[1] NaN NaN NaN NaN NaN NaN NaN NaN
Error in calc_loglike_sp(tip_condlikes_of_data_on_each_state = tip_condlikes_of_data_on_each_state,

Sorry, I am still new to BioGeoBEARS but I did manage to run the example script. Thank you very much for your time.
-Olympia

Nick Matzke

unread,
Jan 26, 2016, 7:09:42 PM1/26/16
to BioGeoBEARS, mat...@nimbios.org
Hi,

If you still get the error, after very carefully making sure you've run the source() commands as instructed on PhyloWiki, email me your files and script.

Cheers!
Nick

Olympia P.

unread,
Jan 26, 2016, 8:18:19 PM1/26/16
to BioGeoBEARS, mat...@nimbios.org
Hello Nick,

Thank you so much for your reply. Unfortunately the errors are still there, I hope my files are okay, I have attached them. Thank you for your help.
-Olympia
Crocsgeog.txt
Crocstree.txt

Nick Matzke

unread,
Jan 26, 2016, 10:19:15 PM1/26/16
to bioge...@googlegroups.com, Olympia P.
Hi Olympia, it all ran fine for me, files and script attached.

I should say -- this looks like a parsimony tree with post-hoc time scaling and thus many ultra-short branches.  Such trees are still fairly common but I think within a few years they won't be usable in publications, because they are likely not a realistic estimate of divergence times or branch lengths.  In this particular case it probably won't matter much as d and e are estimated at 0 -- as these are the only anagenetic, continuous-time parameters, when they are 0, then branch length is irrelevant. On the other hand, with a realistic tree, you might get different estimates (although probably not, as all the tips are single-areas, which tends to support +J models).

My preferred method for time-scaling is BEASTmasteR and Beast2, there are other options though:

Cheers,
Nick


Olympia P.

unread,
Jan 27, 2016, 2:34:07 AM1/27/16
to BioGeoBEARS, domin...@gmail.com, mat...@nimbios.org
Hello Nick,

Thank you so much for your help!! Really appreciate all the information and the BEASTmasteR recommendation, thanks again for taking the time!
-Olympia

James Kitson

unread,
Mar 15, 2016, 2:23:17 PM3/15/16
to BioGeoBEARS, domin...@gmail.com, mat...@nimbios.org
Hello all,

Was there a specific solution for Olympia's error above? I've updated all my libraries, and run all the source() commands and the rest of the code chunk-by-chunk but still the same error. The only real differences from the original sample script are the input files.

Many Thanks,

James

Nick Matzke

unread,
Mar 15, 2016, 2:29:17 PM3/15/16
to bioge...@googlegroups.com, domin...@gmail.com, mat...@nimbios.org
Hi- that's weird, for Olympia the issue seemed fixed when I ran the script with all of the source commands- keeping in mind that the One True List of updates is the example script on the main phylowiki biogeobears page, and older files/scripts won't necessarily have them all.  If you email me your files I can double check. Cheers! Nick

James Kitson

unread,
Mar 16, 2016, 7:15:48 AM3/16/16
to BioGeoBEARS, domin...@gmail.com, mat...@nimbios.org
Hi Nick,

I've attached the files. A bit of background in case this helps; I've performed the dating analysis in MrBayes so the tree is ultrametric but the actual node ages are stored in a separate output file i.e. the branch lengths will look like they are scaled in substitutions. There are some polytomies which I resolved using multi2di(my.tree, random=TRUE) and I've given the new branch lengths a very short length that is still longer than the min_branchlength that would cause BioGeoBEARS to interpret them as a hook. The following code chunk will get you from the attached tree to the tree that fails to plot.

### read in the resolved tree
tree.resolve<-read.nexus("resolved_tree.nex")

### give zero length branches an arbitrarily short length that is higher than the min branch length for BioGeoBEARS
### this prevents BioGeoBEARS from interpreting the ultra short branch as a direct ancestor.
tree.resolve$edge.length<-ifelse(tree.resolve$edge.length==0,0.00001,tree.resolve$edge.length)

Many Thanks,

James

To unsubscribe from this group and stop receiving emails from it, send an email to biogeobears+unsubscribe@googlegroups.com.
resolved_tree.nex
BioGeoBEARS_dist.txt

Nick Matzke

unread,
Mar 16, 2016, 9:56:29 PM3/16/16
to bioge...@googlegroups.com, Olympia P.
Thanks, I'll take a look...

--
You received this message because you are subscribed to the Google Groups "BioGeoBEARS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to biogeobears...@googlegroups.com.
To post to this group, send email to bioge...@googlegroups.com.
Visit this group at https://groups.google.com/group/biogeobears.

Nick Matzke

unread,
Mar 16, 2016, 10:33:02 PM3/16/16
to Nick Matzke, bioge...@googlegroups.com, Olympia P.
Hi,

It worked fine for me, *BUT* I had to:

1. I made sure the geography file was formatted correctly (compare geog.data to your geography file)

2. I made sure your NEXUS file was edited as you coded, AND converted to Newick AND saved as Newick. E.g.:

========================
library(ape)

wd = "/drives/Dropbox/_njm/__packages/BioGeoBEARS_setup/z_help/James_Kitson/"
setwd(wd)

nexfn = "resolved_tree.nex"
tr = read.nexus(nexfn)

### read in the resolved tree
tree.resolve<-read.nexus("resolved_tree.nex")

### give zero length branches an arbitrarily short length 
# that is higher than the min branch length for BioGeoBEARS
### this prevents BioGeoBEARS from interpreting the ultra 
# short branch as a direct ancestor.
tr = tree.resolve
tr$edge.length<-ifelse(test=tree.resolve$edge.length==0, yes=0.00001, no=tree.resolve$edge.length)

write.tree(tr, file="tree.newick")
========================

With those files, and the current script/source files, it seems to work, script, inputs/outputs attached.  

Example input files are here:

If you figure out what caused your issue, let me know...

Cheers!
Nick



notes_v1.txt
James_Kitson_DEC_vs_DEC+J_M0_unconstrained_v1.pdf
script_v1.R
tree.newick
geog.data
BioGeoBEARS_dist.txt
resolved_tree.nex

Nick Matzke

unread,
Mar 16, 2016, 10:55:52 PM3/16/16
to Nick Matzke, bioge...@googlegroups.com, Olympia P.
Also, loose thought -- I am dubious about majority-rules trees in a dated-tree context. What does a polytomy even mean in a dated tree?  What does the date of a polytomy node represent?  The BEAST MCC trees make more sense to me, being one of the sampled tree topologies which are fully resolved...

Cheers,
Nick

James Kitson

unread,
Mar 18, 2016, 8:27:57 AM3/18/16
to BioGeoBEARS, mat...@nimbios.org, domin...@gmail.com
It's a good point. I've always felt a little unsure of MCC trees simply because I think a polytomy is a more obvious way of showing the uncertainty in your data (or it may even be real i.e. speciation at time scales below the resolution of your dataset) but I guess for a biogeographic analysis, why not show the most credible scenario across the sampled trees?

Many Thanks for pointing out the formatting errors.

James
To unsubscribe from this group and stop receiving emails from it, send an email to biogeobears+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages