New update to BioGeoBEARS and stochastic map objects

553 views
Skip to first unread message

Jonathan Drury

unread,
Apr 19, 2023, 7:47:12 AM4/19/23
to BioGeoBEARS
Hey Nick,

I have coded models of trait evolution in the R package RPANDA that use stochastic map outputs from BioGeoBEARS to delineate coexisting lineages. I've noticed, however, that the functions have stopped working since your most recent edit of BioGeoBEARS. Is it correct that the main change is that you have added a new column? Or are there other changes as well? If so, would it be possible to provide a description of those changes so I can update the RPANDA code and get functions up and running again?

Many thanks,

Jonathan

Nick Matzke

unread,
Apr 19, 2023, 6:35:29 PM4/19/23
to bioge...@googlegroups.com
Hi! Apologies for this -- I don't recall adding a column?  I recall fixing a bug which was occurring in some restricted situation where R was reading a 2-element vector as a 2x1 matrix instead of a 1x2 matrix -- "Deal with the case of 1 event, which produces 2,1 matrix instead of nrowsx2 matrix".  This was a few weeks ago.  

There might have been older edits?  But I suspect it was this, and it will be some minor change required to your code?

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 view this discussion on the web visit https://groups.google.com/d/msgid/biogeobears/aa794167-2492-416a-b3f0-a70697ebfc33n%40googlegroups.com.

Ivan Magalhães

unread,
Apr 28, 2023, 2:10:00 PM4/28/23
to BioGeoBEARS
Hi Nick,

Perhaps related to the original post: I updated BioGeoBEARS yesterday, and I am now unable to run BSM using the very same script I used last week with an older version of the package. 
I now get this error:

Beginning stochastic mapping UPPASS (i:Leftnode,j:Rightnode,anc:Ancnode;):
237:122,238:209,anc:121; 235:123,236:201,anc:122; 233:124,234:185,anc:123; 231:125,232:184,anc:124; 229:186,230:79,anc:185; 227:126,228:164,anc:125; 225:210,226:227,anc:209; 223:187,224:78,anc:186; 221:165,222:177,anc:164; 219:127,220:147,anc:126; 217:211,218:225,anc:210; 215:188,216:198,anc:187; 213:166,214:174,anc:165; 211:128,212:144,anc:127; 209:212,210:224,anc:211; 207:189,208:73,anc:188; 205:167,206:48,anc:166; 203:148,204:156,anc:147; 201:129,202:142,anc:128; 199:228,200:237,anc:227; 197:213,198:222,anc:212; 195:190,196:72,anc:189; 193:168,194:47,anc:167; 191:149,192:30,anc:148; 189:130,190:139,anc:129; 187:229,188:235,anc:228; 185:214,186:219,anc:213; 183:202,184:207,anc:201; 181:191,182:196,anc:190; 179:178,180:183,anc:177; 177:169,178:46,anc:168; 175:157,176:161,anc:156; 173:150,174:155,anc:149; 171:131,172:138,anc:130; 169:230,170:113,anc:229; 167:215,168:94,anc:214; 165:203,166:85,anc:202; 163:192,164:68,anc:191; 161:179,162:58,anc:178; 159:170,160:45,anc:169; 157:158,158:35,anc:157; 155:151,156:154,anc:150; 153:132,154:135,anc:131; 151:238,152:120,anc:237; 149:231,150:233,anc:230; 147:220,148:98,anc:219; 145:216,146:218,anc:215; 143:204,144:206,anc:203; 141:199,142:77,anc:198; 139:193,140:195,anc:192; 137:180,138:182,anc:179; 135:175,136:52,anc:174; 133:171,134:173,anc:170; 131:162,132:39,anc:161; 129:159,130:34,anc:158; 127:152,128:25,anc:151; 125:145,126:21,anc:144; 123:140,124:14,anc:139; 121:136,122:8,anc:135; 119:133,120:4,anc:132; 117:239,118:119,anc:238; 115:236,116:116,anc:235; 113:234,114:112,anc:233; 111:232,112:109,anc:231; 109:226,110:106,anc:225; 107:223,108:101,anc:222; 105:221,106:97,anc:220; 103:217,104:91,anc:216; 101:208,102:88,anc:207; 99:205,100:82,anc:204; 97:200,98:76,anc:199; 95:197,96:71,anc:196; 93:194,94:65,anc:193; 91:181,92:55,anc:180; 89:176,90:51,anc:175; 87:172,88:42,anc:171; 85:163,86:38,anc:162; 83:160,84:33,anc:159; 81:153,82:24,anc:152; 79:146,80:20,anc:145; 77:143,78:17,anc:142; 75:141,76:13,anc:140; 73:137,74:7,anc:136; 71:134,72:3,anc:133; 69:117,70:118,anc:239; 67:114,68:115,anc:236; 65:110,66:111,anc:234; 63:107,64:108,anc:232; 61:104,62:105,anc:226; 59:102,60:103,anc:224; 57:99,58:100,anc:223; 55:95,56:96,anc:221; 53:92,54:93,anc:218; 51:89,52:90,anc:217; 49:86,50:87,anc:208; 47:83,48:84,anc:206; 45:80,46:81,anc:205; 43:74,44:75,anc:200; 41:69,42:70,anc:197; 39:66,40:67,anc:195; 37:63,38:64,anc:194; 35:61,36:62,anc:184; 33:59,34:60,anc:183; 31:56,32:57,anc:182; 29:53,30:54,anc:181; 27:49,28:50,anc:176; 25:43,26:44,anc:173; 23:40,24:41,anc:172; 21:36,22:37,anc:163; 19:31,20:32,anc:160; 17:28,18:29,anc:155; 15:26,16:27,anc:154; 13:22,14:23,anc:153; 11:18,12:19,anc:146; 9:15,10:16,anc:143; 7:11,8:12,anc:141; 5:9,6:10,anc:138; 3:5,4:6,anc:137; 1:1,2:2,anc:134;
...finished stochastic mapping UPPASS.
Adding cladogenetic events and re-arranging columns...
DONE adding cladogenetic events and re-arranging columns.
FINISHING stochastic_map_given_inputs().

Success #1/10 on stochastic mapping attempt #1/100 tries.
Error in (length(ana_events_table) > 1) && (is.na(ana_events_table) ==  :
  'length = 370' in coercion to 'logical(1)'


Any ideas?
Thanks,
Ivan

Nick Matzke

unread,
Apr 28, 2023, 10:14:34 PM4/28/23
to bioge...@googlegroups.com
Hiya! Whoops!  I wonder if you could send me a zipfile of the files & script that gave this error, then I can diagnose. Cheers! Nick

Ivan Magalhães

unread,
Apr 29, 2023, 11:44:50 AM4/29/23
to bioge...@googlegroups.com
Hi Nick,

Thanks for looking into this. Please find attached the input files. Today I am working from home, where I have an old version of BioGeoBEARS(Version: 1.1.2, Date: 2019-01-22) and it runs well here...

Best,
Ivan

bsm_bug.zip

Ivan Magalhães

unread,
Jun 8, 2023, 1:08:06 PM6/8/23
to bioge...@googlegroups.com
Hi Nick -- hope all is well. Was it possible to check if this was a bug? Thanks!

Nick Matzke

unread,
Jun 16, 2023, 10:37:38 PM6/16/23
to bioge...@googlegroups.com
Hi -- apologies for the delay on this.  I believe I have fixed the bug now, which occurred in certain scenarios of time-stratified stochastic mapping. 

Re-install from GitHub to get the correction...

Cheers!
Nick

Felipe Durán Garcés

unread,
Jun 17, 2023, 9:01:31 PM6/17/23
to BioGeoBEARS
Hi everyone,

I have the same problem when I run unstratified BSM. I run biogeobears using the parameters by defect.

This is the error:

Error in (length(ana_events_table) > 1) && (is.na(ana_events_table) == :
'length = 592' in coercion to 'logical(1)'

Thanks,

Felipe

Nick Matzke

unread,
Jun 19, 2023, 12:43:11 AM6/19/23
to bioge...@googlegroups.com
Hi!  OK, apologies again for the issues.

What has happened is that something was updated in R, such that some of the checks for different cases in the past (primarily branches with, or without anagenetic events on them) were giving invalid results (e.g. FALSE FALSE instead of just FALSE). 

I have worked through both non-stratified/regular, and time-stratified, Biogeographic Stochastic Mapping, on the example dataset, and gotten both to run without those crashes.

Please:

1. Update R to latest version  (probably not required, but this is what I did) 

2. Update BioGeoBEARS with:

library(devtools)
devtools::install_github(repo="nmatzke/BioGeoBEARS")

3. Restart R and try re-running your BSM script.

Cheers!
Nick






Felipe Durán Garcés

unread,
Jun 20, 2023, 7:15:30 PM6/20/23
to BioGeoBEARS
Hi Nick, 

I took your recommendations and now it's working.

Thanks,

Felipe

Nick Matzke

unread,
Jun 20, 2023, 11:23:59 PM6/20/23
to bioge...@googlegroups.com
Hi all,

I have made a few more updates to the Biogeographic Stochastic Mapping (BSM) code for time-stratified analyses -- it should throw a lot fewer warnings etc. now.  Much of this was improving some things messed up by R updates, and the handling of the case of fossil tips (which do not come all the way up to the present). 

Get the updates from GitHub as follows:

library(devtools)
devtools::install_github(repo="nmatzke/BioGeoBEARS")

Cheers,
Nick

Ivan Magalhães

unread,
Jun 21, 2023, 12:53:42 PM6/21/23
to bioge...@googlegroups.com
Fixed it for me, BSM are now running smoothly! Thanks a lot for the hard work on this.
Best,
Ivan

You received this message because you are subscribed to a topic in the Google Groups "BioGeoBEARS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/biogeobears/NPnR8Z0CK40/unsubscribe.
To unsubscribe from this group and all its topics, send an email to biogeobears...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/biogeobears/CAJdu7BCh%2B4_JaKatjMnOxteHkpXNYCLbR5dnaKDC-pWkb%3DpMUw%40mail.gmail.com.

Luis Carlos Hernandez Salgado

unread,
Sep 4, 2023, 4:59:39 PM9/4/23
to BioGeoBEARS
Hi Nick, thank you for taking the time to see through this. 
I follow your instructions, but i get this error:
Detected NON-stratified input. Running get_inputs_for_stochastic_mapping_from_results_object().
Error in if (is.na(states_list[[i]])) { : the condition has length > 1
Best

CRG

unread,
Nov 26, 2023, 8:05:46 PM11/26/23
to BioGeoBEARS
Hi all,

Jumping on this thread a little late in the game. 

I am running into a problem reproducing some stochastic mapping that has worked for me in the past. When I try to get stochastic mapping inputs I get the same error as the last comment: Error in if (is.na(states_list[[i]])) { : the condition has length > 1. 

This only occurs for models in which I manually input a states list. It appears to stem from a similar issue mentioned above where a conditional check contains a vector of  >1 (FALSE, FALSE). I can circumvent this by changing the check in the function to sum(is.na(states_list[[i]])), but the problem reoccurs downstream in the runBSM function where I'm lost diagnosing the issue.

I have the most recent version of R, BioGeoBEARS, and dependencies installed as of 11/26/23.

Thanks in advance for any guidance on this!

CRG

Nick Matzke

unread,
Nov 26, 2023, 9:36:22 PM11/26/23
to bioge...@googlegroups.com
Thanks folks -- sorry I missed this before, I will check; at some point R got more picky about is.na being applied to something with multiple items in it, I will work to fix it & send an update.

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.

CRG

unread,
Jan 25, 2024, 6:39:46 PM1/25/24
to BioGeoBEARS
Hi Nick,

I just wanted to follow up on this thread to see if you were able to check for lingering is.na issues?

Thanks,
CRG

Benedikt Kuhnhaeuser

unread,
Feb 14, 2024, 7:41:17 AM2/14/24
to BioGeoBEARS
Hi all,

I believe I ran into the same issue when running plot_per_area_probs(). It gives the error:
Error in states_list[[i]] && (length(states_list[[i]] == 1)) : 'length = 2' in coercion to 'logical(1)'

So annoying that those little changes in R seem to incapacitate lots of functionality in BioGeoBEARS!

All the best,
Ben

Nick Matzke

unread,
Feb 14, 2024, 5:26:47 PM2/14/24
to bioge...@googlegroups.com
Eep! I fixed the previous ones from awhile back. I will look at this one in per-area-probs...

Cheers,
Nick

Ben Kuhnhaeuser

unread,
Feb 15, 2024, 6:42:24 AM2/15/24
to bioge...@googlegroups.com

Thank you, Nick!

 

From: bioge...@googlegroups.com <bioge...@googlegroups.com> On Behalf Of Nick Matzke
Sent: Wednesday, February 14, 2024 10:27 PM
To: bioge...@googlegroups.com
Subject: Re: [BioGeoBEARS] Re: New updates to BioGeoBEARS and stochastic map objects 2

 

CAUTION: This email originated from outside the organisation. Do not click links or open attachments unless you recognise the sender and know the content is safe.
Report this email as Suspicious via Kew Service Desk

--
You received this message because you are subscribed to a topic in the Google Groups "BioGeoBEARS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/biogeobears/NPnR8Z0CK40/unsubscribe.
To unsubscribe from this group and all its topics, send an email to biogeobears...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/biogeobears/CAJdu7BDubhmCv%3DYECgyt9zy6smGSBV7OMALYQX1745E_q0zoTw%40mail.gmail.com.



Disclaimer

The information contained in this communication from the sender is confidential. It is intended solely for use by the recipient and others authorized to receive it. If you are not the recipient, you are hereby notified that any disclosure, copying, distribution or taking action in relation of the contents of this information is strictly prohibited and may be unlawful.

This email has been scanned for viruses and malware, and may have been automatically archived by Mimecast Ltd, an innovator in Software as a Service (SaaS) for business. Providing a safer and more useful place for your human generated data. Specializing in; Security, archiving and compliance. To find out more Click Here.

Nick Matzke

unread,
Feb 26, 2024, 4:19:45 PM2/26/24
to BioGeoBEARS
Hi -Ben - I think perhaps I fixed all these before your post:

============
Hi all,

I believe I ran into the same issue when running plot_per_area_probs(). It gives the error:
Error in states_list[[i]] && (length(states_list[[i]] == 1)) :
  'length = 2' in coercion to 'logical(1)'

So annoying that those little changes in R seem to incapacitate lots of functionality in BioGeoBEARS!

All the best,
Ben
============

...as I cannot find the code "(length(states_list[[i]] == 1))" anywhere in that function or related ones.  So it might just be fixed by an update from GitHub.  Please let me know if you have a different experience.

Thanks!
Nick

Sarah Weil

unread,
Mar 4, 2024, 8:39:26 AM3/4/24
to BioGeoBEARS
Hi all,
I'm running into the same problem as CRG above: when running run_BSM on a model where I manually adapted the states list I get
Error in if (is.na(states_list[[i]])) { : the condition has length > 1
It seems like the problem could be in the part where cladogenetic events are added. With the function "add_cladogenetic_events_to_trtable" the ranges list is recalculated from the states list, and a " is.na(states_list[[i]])" is used which throws an error if states_list[[i]] has more than 1 element.
Best,
Sarah

Nick Matzke

unread,
Mar 4, 2024, 4:32:34 PM3/4/24
to bioge...@googlegroups.com
Thanks -- I'll take a look...
Cheers,
Nick

Nick Matzke

unread,
Mar 4, 2024, 4:42:59 PM3/4/24
to bioge...@googlegroups.com
Hi! 

I've edited the code to do the length check on the states_list[[i]] first, and then only check for NA if the length of states_list[[i]] equals 1.

Please update from GitHub and give it a shot...

Cheers,
Nick


On Tue, Mar 5, 2024 at 2:39 AM Sarah Weil <sarahso...@gmail.com> wrote:

Nick Matzke

unread,
Mar 4, 2024, 4:43:47 PM3/4/24
to bioge...@googlegroups.com
i.e.

library(devtools)
devtools::install_github(repo="nmatzke/BioGeoBEARS", dependencies=FALSE)
Reply all
Reply to author
Forward
0 new messages