Pages

Monday 23 June 2014

Transforming NetLogo Simulated Networks into UCINET for Analysis

There's a program called NetLogo. It's an open-source agent-based modeling program. And it's awesome, although you have to spend some time with it. There are some example models that are automatically downloaded into a library when you download the program, and several of them are network simulators (they'll simulate a virus in a network, diffusion of a directed network, the formation of giant components, preferential attachment, etc).

There's a program called UCINET too. It's a social network analysis program which works with a freeware program called NETWORK which allows you to visualize networks. UCINET can only be run on Windows, and you can get a free trial you 60 days. With it, you can take a network generated in NetLogo and run all sorts of network diagnostics and alter your network image in whatever ways you like (I have yet to figure out if there is a way to keep track of the time variable somehow- perhaps as a link or turtle attribute, which could then be input as a node attribute in NETWORK).

They should probably be able to talk to each other, right? And then you could create rules for behavior in your NetLogo, simulate a network on those rules, analyze that network or a set of random simulations, and see if your rules are creating the types of networks you see in reality. That would be pretty cool, not? In the absence of knowing much about programming, here's a semi-labor intensive way to make this happen (doubtless R or some other program can do a lot of this already):

(1) In NetLogo:
File > Models Library > Networks > Preferential Attachment > Open
Select the Procedures tab
At the very top of Procedures, above the setup procedures, add "turtles-own [ my-list-partners; ]"
In the Main Procedures section, in the "to go" command, add "ask turtles [ set my-list-partners ([who] of link-neighbors) ]" just above the "tick" command
Select the Interface tab (and pray you don't see an error message)
Setup
Go until you have a network you like the size of
File > Export > World... > Save it somewhere
(there may be a more efficient way to create an output with just the variables of interest, but the below commands will work as well)

(2) In Excel:
Open the network's csv file you just created
Delete columns B:M
Delete rows 1:13
Delete rows below your initial ego/alter list (everything including and below "PATCHES")
Edit > Replace... > type in "[" into the "Find what:" space, leave "Replace with:" blank > Replace All > OK
type in "]" into the "Find what:" space, leave "Replace with:" blank > Replace All > OK > Close
Select column B (the commands below might depend on your version of Word)
Data > Text to Columns... > Delimited > Next > select "Space" as the delimiter and deselect "Tab" > Next > Finish
Hand select the frame with the data
Copy

(3) In UCINET 6
Data > Date editors > DL Editor
In the DL Editor, select the data tab
Select the first cell
Paste
Under "Data format:", select "Nodelist (1-mode)"
File > Save UCINET dataset > name it and save it somewhere
Close the DL editor
Visualize > NetDraw

(4) In NetDraw (which is automatically downloaded as part of UCINET)
File > Open > Ucinet dataset > Network
Select your file, which will end with ##h
Click OK

You can play with it from there. There's also an ability to upload attributes into NetDraw (like turtle color or breed), or resize nodes according to their degree, or any of a number of other options. If you're network in NetLogo has several components, UCINET can handle that too. I imagine there's some way to do a lot of the data reformatting/exporting/
importing automatically. You could also probably apply a similar alteration in code to other network models within NetLogo and use the same procedures to get it into UCINET.

Best of luck! Let me know if anything interesting comes of this/you find a more efficient way to accomplish the same thing.


Source: http://sexandstats.blogspot.ie/2011/09/network-analysis-transforming-netlogo.html

1 comment:

  1. Nice. I've been putting in some serious time with Netlogo and have been looking for further ways to leverage it. I look forward to trying this out!

    ReplyDelete