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

Temporal Network Analysis with R - errors running code #2868

Open
acrymble opened this issue Feb 23, 2023 · 7 comments
Open

Temporal Network Analysis with R - errors running code #2868

acrymble opened this issue Feb 23, 2023 · 7 comments

Comments

@acrymble
Copy link

  • Temporal Network Analysis with R (tested in English only)
  • Mac, running R v 4.2.2.

I tried the code exactly as posted, and started having divergent results from the tutorial in the section starting "Once we have imported this temporal data".

# Make the temporal network dynamicCollabs <- networkDynamic( thenetwork, edge.spells = PHDynamicEdges, vertex.spells = PHDynamicNodes )

Returned the following:

Edge activity in base.net was ignored Created net.obs.period to describe network Network observation period info: Number of observation spells: 1 Maximal time range observed: 1257.5 until 1325 Temporal mode: continuous Time unit: unknown Suggested time increment: NA

Which I don't think is the expected result, and suggests something went wrong.

From there, the line:

plot(dynamicCollabs)

does not return a similar looking result to the (unnumbered) figure, despite the text saying it should.

Screen Shot 2023-02-23 at 14 42 55

The next code:

filmstrip(dynamicCollabs, displaylabels = FALSE)

gives error message:

No coordinate information found in network, running compute.animation Error in as.matrix.network.adjacency(net, attrname = weight.attr, expand.bipartite = TRUE) : Multigraphs not currently supported in as.matrix.network.adjacency. Exiting.

All further code also returns error messages. I wasn't able to get this to resolve. It did work for me and my students this time last year, so I suspect an issue with either newer R versions or a dependence updating and breaking things.

@rivaquiroga
Copy link
Member

I get the same errors in the Spanish version

@hawc2
Copy link
Contributor

hawc2 commented Mar 24, 2023

This lesson might be outdated now, and may not be easy to update.

It's odd because the first problem sounds related to the data/analysis, whereas the second problem sounds related to outdated software. So at first glance it's not clear if there's two layers of issues here to address.

@ZoeLeBlanc I see you we're a reviewer on this, do you have any thoughts on this bug?

@ZoeLeBlanc
Copy link
Member

Hmm we would need to see the code and data to resolve this issue. Looking at the github repo, seems like this might be a similar issue statnet/ndtv#50 but I'm not seeing anything on that repo to suggest this library is fully deprecated

@jenniferisasi
Copy link
Contributor

May we contact the author in case he's been working with the code lately?

@ZoeLeBlanc
Copy link
Member

Interestingly the issue I posted above was someone trying to work through our lesson 😅 statnet/networkDynamic#14 (comment) . The person claimed that this link https://bomiklee.com/post/making-network-animations-using-ndtv-package/ helped them solve the issue by making a network list (not sure what that means). I did try running some of the lesson code and was able to get the initial plots working (though did have to wrap the plot function in the R View function).

I'm not an R person, so had ChatGPT rewrite the R code from that blogpost into Python:

import pandas as pd
import networkx as nx

nv = len(vtx)

rivlist = []

for i in range(1, 5):
    rivi = riv[riv['no'] == i]
    rivii = rivi[['stateabb1', 'stateabb2']].values
    netyr = nx.Graph()
    netyr.add_nodes_from(vtx['stateabb'])
    
    for edge in rivii:
        netyr.add_edge(edge[0], edge[1])
    
    nx.set_node_attributes(netyr, {node: i for node in netyr.nodes}, 'order')
    rivlist.append(netyr)

#Also, note that in this Python code, the vtx and riv variables should be Pandas DataFrames, corresponding to the R data.frames in the original R code.

def set_vertex_attribute(graph, attribute_name, attribute_values):
    nx.set_node_attributes(graph, attribute_values, attribute_name)

set_vertex_attribute(rivlist[0], 'vtx87', vtx87)

cols1 = []
for i in range(204):
    node = rivlist[0].nodes[i]
    ccode = rivlist[0].nodes[node]['vtx87']
    
    if ccode < 200:
        color = "red"
    elif 200 <= ccode < 400:
        color = "orange"
    elif 400 <= ccode < 630:
        color = "yellow"
    elif 630 <= ccode < 700:
        color = "green"
    else:
        color = "blue"
        
    cols1.append(color)

#In this Python code, the vtx87 variable should be a dictionary with keys as the node names and values as the corresponding attributes from the R code. For example, if in R the names(vtx87) is c("USA", "CAN") and vtx87 is c(2, 20), then in Python, the vtx87 should be {"USA": 2, "CAN": 20}.

I think contacting the author would make sense since this is a pretty chunking block of code to add. Instead of rewriting all the code, we could also ask the author to make the lesson not include multigraphs as an option too.

@anisa-hawes
Copy link
Contributor

Thank you, all. I really appreciate your comments.

I'm happy to write to the author, and ask for their input to move forwards. I will update this Issue when I have further information.

@anisa-hawes
Copy link
Contributor

Note: I have written to the author to explain the Issue and invite their contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants