Software

Most network analysis programmes are restricted to simple undirected binary one-mode static networks. Nevertheless, as I hope the other sections of this site have shown, studying richer types of network data can enable us to uncover and study interesting organising principles as well as measuring networks more accurately. The lack of software programmes to analyse richer forms of network data is forcing many non-programming researchers to simplify their data and remove the richness. To fill this gap, tnet is a package written in the statistical software R that currently can analyse weighted networks, two-mode networks, and longitudinal networks (datasets with time-stamped ties).

To the best of my knowledge, there are no programmes that can both analyse the richer forms of network data and allow users to create their own functions. On the one hand, programmes like UCINET and Pajek have a small set of functions for weighted and two-mode networks, but they do not allow users to programme additional functions (Batagelj and Mrvar, 2007; Borgatti et al., 2002). Therefore, researchers proposing new measures must create stand-alone programmes to deal with a single aspect of weighted networks (e.g., Brandes, 2001; Newman, 2001; Opsahl et al., 2008; Opsahl and Panzarasa, 2009). On the other, a number of packages for analysing networks has been created within the open-source statistical programme R, notably the sna and statnet-packages (Butts, 2006; Handcock et al., 2003). These packages allow researchers to create additional functions on top of existing ones. This ability reduces the time spent on programming greatly, and let researchers focus on the contribution to the literature instead. For example, if someone has already written a function for identifying the shortest paths in a network, a researcher that would like to extend this measure can simply work on this code without programming the function from scratch. However, the sna and statnet-packages rely on the basic network-package for data structures to represent networks (Butts et al., 2008). This basic package does not have data classes for weighted, two-mode, and longitudinal networks. Therefore, to ease the development of new functions for these networks, a new platform is needed. tnet represent an attempt to create such a platform. Although it is a user-written package in R, it does not rely on the network-package.

Getting tnet

Compiled versions and the source code of tnet are available through the CRAN servers. If you are using the Windows version of R, you should be able to install tnet by going to the ‘Package’-menu in R, opening ‘Install package(s)’, selecting a server close to you, and then, choosing ‘tnet’ from the list. For specific details on how to install, update, and load tnet, see the installation-page.

Data structures

Network data is handled in an edgelist format in tnet. This is a rectangular format where each row is a tie. The edgelist format is more efficient when networks are sparse (the number of ties is much smaller than the number of nodes squared). The functions can also read one-/two-mode matrices with more than 4 nodes; however, these will automatically be converted to edgelists. Unlike other R-packages, tnet does not utilise special object classes. It simply use a data frame, which increase transparency and -hopefully- helps researchers understand which data is analysed.

For one-mode networks, the data frame should have three columns where the first column contains the sender or originator of the tie, the second column contains the receiver or target node of the tie, and the third column containing the tie weight. Do note that for undirected networks, each tie must be mentioned twice (once in each direction). Read more…

Two-mode networks should be represented as either a two- or three-column data frame where the first column contain the primary or top nodes, the second column contains the secondary or bottom nodes, and the optional third column containing tie weights. As weighted two-mode network can be confused with weighted one-mode networks, it is important to run as.tnet(net, type="weighted two-mode tnet") before using any analysis functions. Read more…

Longitudinal data should represented by a four column object. The columns correspond to (1) the timing using the following format surrounded by quotes: “YYYY-MM-DD HH:MM:SS”, (2) the sender or originator of the tie, (3) the receiver or target node of the tie, and (4) the tie weight. Unlike the one-/two-mode formats, the tie weight can take negative values, which signal a weakening of the tie. Read more…

Implemented Functions

The various network measures are covered in their respective sections of this website and the R-documentation. Additionally, there are a number of functions for transferring network data between programmes available.

Datasets

For the convenience of tnet users, I have collected a number of network datasets that were available on the Internet, and made them conform to the required standard. Please do cite the mentioned reference if you use a dataset. It is possible to downloaded the networks in their native form and transformed versions. For example, the Facebook-like Social Network is available as a longitudinal one-mode network (native form) and as a static one-mode network. Read more…

Licensing

tnet, as the information on this blog, is published under the Creative Commons Attribution-Noncommercial 3.0-lisence. This means that you are free to:
· share (copy, distribute and transmit)
· remix (adapt)
under the following conditions:
· attribution (you must cite or link to it)
· noncommercial (you may not use it for commercial purposes; contact me).

If you use tnet, please cite: Opsahl, T., 2009. Structure and Evolution of Weighted Networks. University of London (Queen Mary College), London, UK, pp. 104-122. Available at https://toreopsahl.com/publications/thesis/.

Like this:

Dear Tore,
You made an amazing advance in the network analysis. Thanks for sharing good stuffs.
I have been working a longitudinal network analysis using your “weighted_richclub_w()”. But, i am having consistent warnings and errors. Spending some hours on your R scripts, I found that my data could not get through your “phi ()”. I spent hours on it, but because of my short knowledge about R, I still have several lines in your codes that I could’nt understand. Could you explain a little bit more about the following two lines in your phi function? Especially, I am having a problem to get through the second line.

The phi-function is the non-normalized weighted rich-club coefficient. The line starting with Er finds the ties within the prominent nodes. This should always be a list-object, so in tnet 3.1, sapply has been changed to lapply. The second line sum the tie weights of these ties.

Dear Tore sir,
I am very interested in SNA as my research area. I am new to it, and luckily i found this webspace :-) You have done remarkable work.
There is too much to learn as am new to it. I have a confusion as to where to start from? I am doing my Masters in Computer Science from National Institute of Technology, Surat. Could you plz help me in drawing a path?

I will keep in touch and follow your work to get in detail of this area. It would be great boost if you could guide me sir. (I know you are a busy person, still i ask you :-D) I just loved your work.

Hello Tore
I came across a problem in using the Betweeness_w of tnet and it would be appreciated if you please help me with that:

I am interested to use the tnet package in order to calculate Betweenness Centrality for a weighted and undirected network. My network has 1309 nodes and 4229 links. I also add the reverse relationship between nodes to get the tnet to treat my network as an undirected one.

When I run the betweenness_W in R, it only gives me the BC value for the node 1 to 1308 and the last one (node id=1309) is missing. Do you have any idea what is the reason for this?

There has been an update of the tnet package recently. Could you run update.packages() to ensure you have version 3.0.7? If you are experiencing similar problems, email me with the code and data you are using.

Thanks so much for your response. I tried the recent version as well but still received the same results (the last node is missing). I emailed you the link table and the code. Could you please have a look at them?

Thanks for your comment. I don’t know of other packages specifically for weighted and directed networks. However, all but one function in tnet works on directed and weighted networks (the local clustering coefficient is not defined for directed networks; hence, only implemented for undirected ones).

Hi Tore, thanks for sharing such good stuff.
I was using the function degree_w() with a dataset containing long ids (6 digits) and it was returning strange results: my network has 3700 nodes, and it was returning a data frame with more than 50000 observations. Once a replaced the ids for shorter ones the function works a treat. Is there really a restriction for the size of ids the function can handle?

The degree_w-function is not restricted in any way to small node ids; however, the return object includes all nodes from 1 to the maximum integer. The nodes ids without a mentioned in the edgelist will get a degree score of 0 (i.e., isolates). To overcome this issue, you can use the compress_ids-functions before running the degree_w-function. For example:

Dear Tore, many thanks for this. It’s way faster than what I was doing.
Aline

15.Jesse | September 30, 2014 at 3:23 am

Hi Tore,

Thank you so much for your work in SNA. I am trying to run a longitudinal, weighted, multi-relational (multiplex), network in R with one node type. Everyone tells me this is not possible with any packages out there. Will Tnet do this? I need to pull network metrics from the graph that take into account the complete network with multi-relations.

Glad that you are attempting to tackle more advanced types of networks. tnet can analyze some of those features individually, but it is not destined for multiplex networks. This is more out of a lack of metrics to apply to these networks. I’m afraid you will have to start coding up some metrics yourself if you want to go down this path.

Dear Tore,
Thanks for the beautiful work you are doing. I am currently trying to analyse some two mode network (firms and their stakeholders). I was wondering if you have any suggestions for calculating clustering, density (of row and columns), point connectivity, decay centrality.

Dear Tore,
Thank You very much for your work.
I\m new with R, so I have alredy tried to learn sites You have adviced for understanding it. But even after it I haven’t managed to solve my very simple (I thnink) task. I have a weighted network and need just to visualize it. I have data both in form of text file with edge list and a metrix in excel.
Could You please help me?

Thank You for much for your answer! I will try it. And let me plz one more question. Maybe there is some list of all possible fuctions for tnet or only that one which is in help file (in R) available?
Thank You!

22.Nina | March 28, 2015 at 7:31 pm

And one more question, please. I have a dynamic cognitive map, so there are some negative values for edges. Is tnet possible to work with it?

The first argument “net” is required to be a weighted edgelist according to the document. However, when I use a weighted matrix it seems working fine. I am wondering if this is true. Is this because the following rules apply here?

“If the data-object has two-columns, it is assumed to be a binary two-mode network; three columns, weighted one-mode network; four columns, longitudinal; five or more and the same number of rows and columns, weighted one-mode network; five or more and –not– the same number of rows and columns, it is assumed to be a two-mode network.”

Dear Tore,
Thank you so much for sharing your work, I found it extremely useful and I think is very important we share in order to avoid repeating ourselves all the time.

I am finding a problem, though and I am not sure if its related with your code or I am just doing something wrong. I am reading the output matrix from my C programme and storing it in a r matrix (myMatrix) first, but when trying to do:

I am doing my project of Epistemic network analysis which deals with weighted networks and its statistical analysis. I would like to ask you couple of questions regarding my project. Could you share me your email id?