[statnet_help] [EXTERNAL] Re: Issue with delete.vertices and network.extract.with.lasttoggle

Zhu, Lin via statnet_help statnet_help at u.washington.edu
Tue Sep 16 12:53:29 PDT 2025


Hi Steve and statnet team,

Thank you so much for your help! I really appreciate it!

I have coded a simple example (attached), and attached the initial dynamic network and the fitted STERGM to be used in the example. Please let me know if you can replicate the error or have any questions. Thanks a lot!!

Best,
Lin

From: Steven M. Goodreau <goodreau at uw.edu>
Date: Monday, September 15, 2025 at 7:26 PM
To: Zhu, Lin <l.zhu3 at med.miami.edu>, statnet_help at u.washington.edu <statnet_help at u.washington.edu>
Subject: [EXTERNAL] Re: [statnet_help] Issue with delete.vertices and network.extract.with.lasttoggle
CAUTION: This email originated from outside the organization. DO NOT CLICK ON LINKS or OPEN ATTACHMENTS unless you know and trust the sender.

Hi Lin,

A few of us have taken a look at this and still don't have a clear answer on the behavior or your potential fix. Carter seems confident it's not an issue in network but something upstream that calls it. I'm not able to reproduce it.

Are you able to create a minimum reproducible example? Then we can dive in a lot more deeply.

Thanks,

Steve




On 8/25/2025 3:05 PM, Zhu, Lin via statnet_help wrote:
Dear Statnet community,

Hope everyone is doing great!

I’ve been using Statnet for a few years, and I’m looking to see if anyone had this same error and if it can be fixed. So in a summary I have had this error <simpleError in lttails[w2] <- ltheads[w2]: NAs are not allowed in subscripted assignments> from the network.extract.with.lasttoggle function since I updated ERGM from 3.11 to 4.9.0, and TERGM from 3.7.0 to 4.2.2.

I then found that it’s associated with delete.vertices, which I use to remove nodes when they die. So only after using this function, simulating nwd again (S3 used is simulate.networkDynamic) will throw the error. What happened is that, after deleting the nodes, the ties attached to them became NULL in mel. And the network.extract.with.lasttoggle function has the following code to record edge heads and tails which are further processed to construct lttails and ltheads (mentioned in the error message):
valid_eids <- valid.eids(nwd)
tails <- unlist(lapply(nwd$mel, "[[", "outl"))[valid_eids]
heads <- unlist(lapply(nwd$mel, "[[", "inl"))[valid_eids]
The issue is, lapply(nwd$mel, "[[", "outl") outputs all vids from mel, including the NULLs. Then unlist(lapply(nwd$mel, "[[", "outl")) automatically removes the NULLs and ends up with a shorter vector, making the edges and indices not matching anymore. Then having the indices [valid_eids] after and outside of unlist will create NAs at the end of tails, with the number of NAs equal to the number of edges that were attached to the removed nodes (the NULL edges).

A simple fix I think is
tails <- unlist(lapply(nwd$mel, "[[", "outl")[valid_eids])
heads <- unlist(lapply(nwd$mel, "[[", "inl") [valid_eids])

However I tried different methods to replace the code, but it either doesn’t use my updated code, or R crashes if I edit the tergm namespace or Rprofile. Since this function is wrapped many layers under simulate, I didn’t find a better way to replace it.

So has anyone had the same issue? Does my debugging make sense? If it’s a common issue, would it be possible to update the function in the package from the statnet side so it won’t crash? Please feel free to reach out if you have any questions. Thank you so much for your help!

(A bit more context of the package updates: I used to use renv to lock the package versions (thanks to Steve’s suggestion) and had no issues. Recently I got a new Mac, which cannot install older R versions written with Rosetta, and renv failed to install the older packages because the newer R defaults to clang instead of gcc in many places, which caused a lot of installation errors. I tried to manually install the packages with no luck. I hence decided to update my statnet to the new versions.)

Best,
Lin



_______________________________________________

statnet_help mailing list

statnet_help at u.washington.edu<mailto:statnet_help at u.washington.edu>

http://mailman23.u.washington.edu/mailman/listinfo/statnet_help<https://urldefense.com/v3/__http:/mailman23.u.washington.edu/mailman/listinfo/statnet_help__;!!KVu0SnhVq1hAFvslES2Y!PnYvP4AXoCjRAJ5Qsck3dQcCQrzO93AXbtTABPkRJTRTttTVtEzLzDMDIYMfJ-hRlz05eYPeFNx8MvqIviAeTw$>

--

******************************************************************************************************

Steven M. Goodreau / Professor, Dept. of Anthropology / Adjunct Prof., Dept. of Epidemiology

(STEE-vun GOOD-roe) / he-him / https://faculty.washington.edu/goodreau<https://urldefense.com/v3/__https:/faculty.washington.edu/goodreau__;!!KVu0SnhVq1hAFvslES2Y!PnYvP4AXoCjRAJ5Qsck3dQcCQrzO93AXbtTABPkRJTRTttTVtEzLzDMDIYMfJ-hRlz05eYPeFNx8MvoNvdfoSA$>

Physical address: Denny Hall M236; Mailing address: Campus Box 353100 / 4216 Memorial Way NE

University of Washington / Seattle WA 98195 / dzidzəlalič, x̌ʷəlč

******************************************************************************************************

For there is always light, if only we’re brave enough to see it. If only we’re brave enough to be it.

- Amanda Gorman, The Hill We Climb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman23.u.washington.edu/pipermail/statnet_help/attachments/20250916/772c18df/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: debug_delete_vertices.R
Type: application/octet-stream
Size: 2044 bytes
Desc: debug_delete_vertices.R
URL: <http://mailman23.u.washington.edu/pipermail/statnet_help/attachments/20250916/772c18df/attachment-0003.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nwd1.rda
Type: application/octet-stream
Size: 52467 bytes
Desc: nwd1.rda
URL: <http://mailman23.u.washington.edu/pipermail/statnet_help/attachments/20250916/772c18df/attachment-0004.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ergm_fit_7_stergm_1373_new.rda
Type: application/octet-stream
Size: 131290 bytes
Desc: ergm_fit_7_stergm_1373_new.rda
URL: <http://mailman23.u.washington.edu/pipermail/statnet_help/attachments/20250916/772c18df/attachment-0005.obj>


More information about the statnet_help mailing list