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).

References

Barrat, A., Barthelemy, M., Pastor-Satorras, R., Vespignani, A., 2004. The architecture of complex weighted networks. Proceedings of the National Academy of Sciences 101 (11), 3747-3752. arXiv:cond-mat/0311416

Batagelj, V., Mrvar, A., 2007. Pajek: Program for Large Network Analysis: version 1.20. http://pajek.imfm.si/.

Borgatti, S. P., Everett, M. G., Freeman, L. C., 2002. Ucinet for Windows: Software for Social Network Analysis. Analytic Technologies, Harvard, MA.

Brandes, U., 2001. A Faster Algorithm for Betweenness Centrality. Journal of Mathematical Sociology 25, 163-177.

Butts, C. T., 2006. sna-package: Package for Social Network Analysis. R package version 1.4.

Butts, C. T., Handcock, M. S., Hunter, D. R., 2008. network: Classes for Relational Data. http://statnet.org/.

Dijkstra, E. W., 1959. A note on two problems in connexion with graphs. Numerische Mathematik 1, 269-271.

Freeman, L. C., 1978. Centrality in social networks: Conceptual clarification. Social Networks 1, 215-239.

Handcock, M. S., Hunter, D. R., Butts, C. T., Goodreau, S. M., Morris, M., 2003. statnet: Software Tools for the Statistical Modeling of Network Data. http://statnetproject.org.

Newman, M. E. J., 2001. Scientific collaboration networks. II. Shortest paths, weighted networks, and centrality. Physical Review E 64, 016132.

Opsahl, T., 2013. Triadic closure in two-mode networks: Redefining the global and local clustering coefficients. Social Networks 35, doi:10.1016/j.socnet.2011.07.001.

Opsahl, T., Agneessens, F., Skvoretz, J., 2010. Node centrality in weighted networks: Generalizing degree and shortest paths. Social Networks 32 (3), 245-251.

Opsahl, T., Colizza, V., Panzarasa, P., Ramasco, J. J., 2008. Prominence and control: The weighted rich-club effect. Physical Review Letters 101 (168702). arXiv:0804.0417.

Opsahl, T., Panzarasa, P., 2009. Clustering in weighted networks. Social Networks 31 (2), 155-163.

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/.

31 Comments Add your own

  • 1. Seung Joon Jun  |  May 26, 2012 at 8:36 am

    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.

    (1) Er <- sapply(output[, "x"], function(a) which(net[, "rc"] > a))
    (2) output[, "num"] <- unlist(lapply(Er, function(a) sum(net[a,"w"])))

    It would be very helpful for me if I get several words from you about this.
    Thank your time, and Best

    Joon.

    Reply
    • 2. Tore Opsahl  |  May 29, 2012 at 5:11 pm

      Hi Joon,

      Thanks for using tnet!

      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.

      Hope this helps,
      Tore

      Reply
  • 3. Harsh Thakkar  |  June 9, 2012 at 12:25 pm

    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.

    Thanks already,

    Warm Regards,
    Harsh

    Reply
    • 4. Tore Opsahl  |  June 11, 2012 at 5:59 pm

      Thanks for the comment and email, Harsh. Hope you find the email reply useful. Best, Tore

      Reply
  • 5. Fatemeh  |  July 17, 2012 at 4:45 am

    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?

    Kind Regards,
    Fatemeh

    Reply
    • 6. Tore Opsahl  |  July 17, 2012 at 7:26 pm

      Hi Fatemeh,

      Thanks for using tnet!

      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.

      Best,
      Tore

      Reply
  • 7. Fatemeh  |  July 18, 2012 at 12:39 am

    Hi Tore

    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?

    Many thanks for your help,
    Fatemeh

    Reply
    • 8. Tore Opsahl  |  July 18, 2012 at 11:25 am

      Hi Fatemeh,

      Thank you for your email and data. This happens because node 1309 is an isolate, and is not kept when the as.tnet-function is automatically run on the edgelist (it deletes tie weights of 0). If you would like to have an isolate included, please put it into the middle of the edge id sequence. This process is shown here: https://toreopsahl.com/2010/03/20/closeness-centrality-in-networks-with-disconnected-components/

      Hope this helps,
      Tore

      Reply
      • 9. Fatemeh  |  July 20, 2012 at 1:21 am

        Hi Tore

        Yes, you’re right. That node id was an isolate and so the BC value should be 0.0.

        Thanks so much for your helpful advice. I could not have come up with this myself.

        Best Regards,
        Fatemeh

  • 10. Majom  |  July 31, 2012 at 8:35 am

    Hi Tore,

    thanks for your efforts.

    Do you have any hints for analyzing weighted directed networks in R?

    Best,
    Majom

    Reply
    • 11. Tore Opsahl  |  July 31, 2012 at 8:40 pm

      Hi Majom,

      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).

      Best,
      Tore

      Reply
  • 12. amsmen  |  February 11, 2014 at 8:22 pm

    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?

    Best,
    Aline

    Reply
    • 13. Tore Opsahl  |  February 11, 2014 at 11:28 pm

      Hi Aline,

      Thanks for your comment.

      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:

      # Load tnet
      library(tnet)
      
      # Load network 
      net <- rbind(
      c(1000,2000,4),
      c(1000,3000,2),
      c(2000,1000,4),
      c(2000,3000,4),
      c(2000,4000,1),
      c(2000,5000,2),
      c(3000,1000,2),
      c(3000,2000,4),
      c(4000,2000,1),
      c(5000,2000,2),
      c(5000,6000,1),
      c(6000,5000,1))
      
      # Compress ids
      net.c <- compress_ids(net, type="weighted one-mode tnet")
      
      # Compute degree scores
      out <- degree_w(net.c[[1]])
      
      # Convert back to original scores
      dimnames(net.c[[2]])[[2]] <- c("nodeID","node") 
      out <- merge(out, net.c[[2]])
      
      # Output out-object
      out[,c("nodeID", "degree", "output")]
      
        nodeID degree output
      1   1000      2      6
      2   2000      4     11
      3   3000      2      6
      4   4000      1      1
      5   5000      2      3
      6   6000      1      1
      

      Hope this helps,
      Tore

      Reply
      • 14. amsmen  |  February 13, 2014 at 9:25 am

        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.

    Thank you!
    Jesse

    Reply
    • 16. Tore Opsahl  |  October 1, 2014 at 1:08 pm

      Hi Jesse,

      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.

      Best,
      Tore

      Reply
  • 17. George Acheampong  |  October 7, 2014 at 9:08 am

    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.

    Best, George

    Reply
  • 19. Nina  |  March 24, 2015 at 8:31 pm

    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?

    Best regards,
    Nina

    Reply
    • 20. Tore Opsahl  |  March 26, 2015 at 2:03 am

      Hi Nina,

      To visualize a network, I would recommend NetDraw for beginners or Gephi. tnet is only for the analysis of networks.

      Good luck!
      Tore

      Reply
      • 21. Nina  |  March 27, 2015 at 6:32 pm

        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?

    Reply
    • 23. Tore Opsahl  |  March 30, 2015 at 6:50 pm

      Hi Nina.

      The documentation in R is a collection of all functions (type ?tnet after library(tnet)).

      Currently, no function is implemented to deal with negative tie weights, and as such, they cannot be analyzed.

      Good luck,
      Tore

      Reply
  • 24. Hang Xiong  |  March 31, 2015 at 3:56 pm

    Dear Tore,

    Thank you very much for sharing your work.

    Can you please confirm if my understanding with the argument “net” is correct in the primitives such as

    betweenness_w(net, directed=NULL, alpha=1)
    clustering_w(net, measure = “am”)
    distance_w(net, directed=NULL, gconly=TRUE, subsample=1, seed=NULL)

    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.”

    Thank you in advance.

    Best,
    Hang

    Reply
    • 25. Tore Opsahl  |  March 31, 2015 at 5:43 pm

      I am glad you’re finding the package useful, Hang.

      Indeed that is the correct interpretation.

      Good luck,
      Tore

      Reply
  • 26. myradio  |  March 9, 2016 at 8:51 am

    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:

    net<-as.tnet(myMatrix)
    or
    net<-as.tnet(myMatrix, type="weighted one-mode tnet")

    it takes extremely long times .

    This matrix is not sparse. In my case it is a NxN matrix with N=2000, hence, the edge list has roughly less than 12 million elements.

    My question is: it is normal to take that long, I am doing something wrong or the code is just not suitable for non-sparse matrices?

    Regards,

    Thank you for your time

    Reply
    • 27. Tore Opsahl  |  March 11, 2016 at 3:36 am

      Hi there,

      tnet is optimized for sparse matrix networks. What functions would you like to use?

      Also, you might want to look into using SNAP (http://snap.stanford.edu/snap/index.html) if your network is already in C/C++.

      Best,
      Tore

      Reply
  • 28. rathnesh  |  June 9, 2016 at 10:57 am

    Hello Tore,

    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?

    Thanks,

    Rathnesh

    Reply
    • 29. Tore Opsahl  |  June 14, 2016 at 5:52 pm

      Rathnesh,

      My email address is on the About-page.

      Tore

      Reply
  • 30. Victor  |  October 25, 2016 at 2:33 pm

    Hi Tore,

    How to read a .graphML file in tnet?

    There are a shortest path to do this?

    Víctor

    Reply
    • 31. Tore Opsahl  |  October 26, 2016 at 4:59 pm

      Hi Victor,

      There are no specific way for importing graphML files in tnet. If you figure it out, leave a comment here so others can learn for it too.

      Best,
      Tore

      Reply

Leave a comment

Subscribe to the comments via RSS Feed