Hi,

The native format of tnet is edgelists. The as.tnet-function can convert matrices to edgelists, but require more than 4 nodes not to confuse with the other network types.

Best,

Tore

I have a question about the usage of as.tnet

My data is a matrix with four columes, and I want to conform it to a network which is a weighted one-mode network with tnet standards.

Then I wrote this ( b is a matrix ):

a<-as.tnet(b,type="weighted one-mode tnet")

however, I kept getting the following error message:

Error in as.tnet(b, type = "weighted one-mode tnet") :

Type of network not recognised

And if I edited it to this:

a<-as.tnet(b,type=NULL)

I got the following error message:

Error in as.tnet(b, type = NULL) : Not all node id's are integers

In addition: Warning message:

In as.tnet(b, type = NULL) :

Data assumed to be longitudinal tnet (if this is not correct, specify type)

Can you point out what I am doing wrong?

Thank you very much!

]]>Hi Stefano,

All links in tnet are considered strengths.

Hope this helps,

Tore

Thank you very muchs

]]>Network data is handled as an edgelist in tnet. If you supply an adjacency matrix, it is converted. However, the node ids must be integers instead of character strings. Have a look at this page: https://toreopsahl.com/tnet/software/one-mode-data-structure/

Good luck!

Tore

Hi Tore, Thanks for the answer :)

May I please ask another question ?

I have a weighted edgelist :

Person1 Person2 Weight

[1,] “A” “B” “1”

[2,] “B” “D” “2”

[3,] “B” “C” “3”

[4,] “C” “D” “4”

Your package seems to indicate we must use a adjacency matrix.

I modified my edgelist to a adjacency matrix (name: adj_test_tr)

A B D C

A 0 1 0 0

B 1 0 2 3

D 0 2 0 4

C 0 3 4 0

as soon as I entered the command : clustering_w(adj_test_tr) i got this problem clustering_w(adj_test_tr)

Error in as.tnet(net, type = “weighted one-mode tnet”) :

Type of network not recognised

Then, I wrote to check if the format is ok

as.tnet(adj_test_tr)

Error in as.tnet(adj_test_tr) :

A node id’s below 1 is detected. The lowest possible node id is 1.

In addition: Warning message:

In as.tnet(adj_test_tr) :

Data assumed to be longitudinal tnet (if this is not correct, specify type)

My network is a simple weighted network (one-mode).

What is the proper format to ensure the clustering_w command works?

Thanks again!

Léanne

]]>Hi Léanne,

Glad you’re finding it useful. If you calculate the clustering coefficient with the arithmetic mean and with the sum of triple weights, you will get the same outcome due to it being a ratio. The difference is that both the numberator and denominator will be double in the latter case.

Best,

Tore

This post is very useful. Thanks very much! I was wondering if there was a possibility to calculate a global clustering coefficient based on a weighted network with your package tnet, and considering the sum of the weighted edges (of triplets) instead of the arithmetic mean, geometric mean, maximum and minimum value.

Thanks very much !

Léanne

Hi Dennis,

The clustering coefficient is available in R and C++. Please drop me an email for the C++ code or find the R code in tnet (which is on CRAN).

The clustering coefficient is always 1 on completed graph due to all triplets being closed.

Best,

Tore

I am currently conducting research on a database with undirected and weighted networks, and would greatly appreciate it if I can use your generalized clustering coefficient. As mentioned in the publication, could I possibly receive a copy of the Matlab code for doing so?

Also, is there no way to calculate the clustering coefficient for a complete graph besides setting a threshold for the edge weights and dichotomizing the network?

Thanks so much,

Dennis

Thanks a lot. I got it.

Date: Thu, 4 Aug 2016 12:14:52 +0000

To: akhlaq1973_pk@hotmail.com

Hi Akhlaq,

The denominator in the binary local clustering coefficient is the number of triplets centered on the focal node (B). These triples are A-B-C, A-B-D, A-B-E, C-B-D, C-B-E, and D-B-E. It can also be calculated as N*(N-1)/2 when N the number of neighbors in undirected networks.

Hope this helps,

Tore

Hi Tore,

I was confused about the local clustering coefficient of node B that is 1/6. There is one tie between neighbours A and C so the numerator is 1, How we get 6 at the denominator?

Hi Abdul,

There are three closed triplets in the above example among nodes A, B, and C. These triplets have the following values on their ties {4,2}, {2,4}, and {4,4}. The geometric mean method for computing triplet values takes the square root of the product of the tie weights (e.g., sqrt(4*2)=2.83). As such, the closed triplets in the above example have the following triplet values using the GM method: 2.83, 2.83, and 4. The sum of these values is 9.66, which is the numerator.

The minimum method simply takes the minimum tie weight. In the above example, this would be: 2, 2, 4, 1, 1, 2, 2, 1, and 1. The sum of the closed ones (the first three) is 8, and the sum of all of them is 16. Hence, the clustering coefficient is 8/16 or 0.5 when using the minimum method. The maximum method is identical, but takes the maximum of the two tie weights instead.

Hope this makes it clearer,

Tore

I have two questions in above given reply to Hang. First how the value of numerator in geometric mean is 9.66?

second, can you give one example for minimum and maximum method as you have given for AM and GM. I’ll always remain thankful. Regards,

It seems your calculations is based on arithmetic mean and the numbers reported in the paper is geometric mean.

From an undirected perspective, there are 9 triplets in these network. For Figure 1a, the triplets and their arithmetic and geometric mean-based values are:

i j k wij wjk vAM vGM closed 1 B C A 4 2 3.0 2.83 TRUE 2 C A B 2 4 3.0 2.83 TRUE 3 C B A 4 4 4.0 4.00 TRUE 4 D B A 1 4 2.5 2.00 FALSE 5 D B C 1 4 2.5 2.00 FALSE 6 E B A 2 4 3.0 2.83 FALSE 7 E B C 2 4 3.0 2.83 FALSE 8 E B D 2 1 1.5 1.41 FALSE 9 F E B 1 2 1.5 1.41 FALSE

The fractions are 10/24 = 0.4167 and 9.66/22.14 = 0.4361.

Hope this helps,

Tore

Hi Tore,

Thank you for your reply.

I tied to calculate the clustering coefficients of the two sampled networks (Figure 1 (a) and (b)), but get slightly different results. I am wondering if I do not understand the algorithm correctly. The following are my calculation.

Figure 1 (a) Network where stronger triplets are closed

Closed triplets: B→A←C; A→B←C; A→C←B

value of closed triplets: 3+4+3=10

Open triplets: A→B←D; A→B←E; C→B←D; C→B←E; D→B←E; B→E←F

value of open triplets: 2.5+3+2.5+3+1.5+1.5=14

Clustering coefficient: 10/(10+14)=0.4167

Figure 1 (b) Network where weaker triplets are closed

Closed triplets: B→A←C; A→B←C; A→C←B

value of closed triplets: 1.5+1+1.5=10

Open triplets: A→B←D; A→B←E; C→B←D; C→B←E; D→B←E; B→E←F

value of open triplets: 2.5+1.5+2.5+1.5+3+3=14

Clustering coefficient: 4/(4+14)=0.2222

Best,

Hang

Hi Hang,

Glad you find the site useful.

The clustering coefficient will always be 1 for fully connected networks. This is because all triplets are closed, and thus the triplet value (however calculated) of all triplets are part of the numerator. As the denominator is the sum of all triplet values, the numerator is the same as the denominator, hence a ratio of 1.

Hope this helps,

Tore

Your website is very useful to learn the characteristics of weighted networks. Thanks a lot for your effort.

I do not quite understand how the weighted global clustering coefficient is calculated, specifically, how the weights are taken into account. In the original paper, you calculate the C_ω,gm of two sampled networks (Figure 1 (a) and (b)), the results are 0.44 and 0.23 respectively. Can you please explain how the results are calculated?

I have a network (denoted as NET) consisting of a number of fully connected clusters, i.e., all nodes are connected to one another in the clusters. The weights are normalized, so the values of weights are between 0 and 1. I obtain clustering_w(NET) = 1. I’m wondering how to interpret the result. This is obvious if NET was a binary network. Since a weight will be add when calculating the weighted clustering coefficient, I though the result should not 1 any more. Can you please guide me here?

Many thanks,

Hang

Hi Juan,

Glad you have found the site useful!

The maximum and minimum methods for the global clustering coefficient do not refer to the maximum or minimum value of the coefficient. They are methods for calculating the triplet value. See the table with the two black-and-white triplets. It is important to recognize that the triplet method affect both the numerator and the denominator of the coefficient. The minimum method produces lower numerator and denominator than the maximum one (except if all tie weights are equal; binary network).

You might also think about the different values in terms of the value assigned to heterogeneous triplets (i.e., the two ties weights are different). The greater the difference between the tie weights, the greater the impact of changing the method. I would recommend that you hack the code for the clustering coefficient to return the numerator and denominator separately. The code below will print these values.

Best,

Tore

# Load tnet library(tnet) # Get network and name it net for simplicity data(tnet) net <- celegans.n306.net # Compute two-mode clustering when the women are primary nodes clustering_w(net, measure=c("bi","am","gm","ma","mi")) # Updated function clustering_w_ND <- function (net, measure = "am") { if (is.null(attributes(net)$tnet)) net <- as.tnet(net, type = "weighted one-mode tnet") if (attributes(net)$tnet != "weighted one-mode tnet") stop("Network not loaded properly") if (length(measure) < 1) stop("You must specify a measure") for (i in 1:length(measure)) if (!(measure[i] %in% c("bi", "am", "gm", "ma", "mi"))) stop("You must specify a correct measure") net <- net[order(net[, "i"], net[, "j"]), ] dimnames(net)[[2]] <- c("i", "j", "wij") tmp <- net dimnames(tmp)[[2]] <- c("j", "k", "wjk") tmp <- merge(net, tmp) index <- tmp[, "i"] != tmp[, "k"] tmp <- tmp[index, ] tmp <- tmp[, c("i", "k", "wij", "wjk")] dimnames(net)[[2]] <- c("i", "k", "wik") net[, "wik"] <- TRUE tmp <- merge(tmp, net, all.x = TRUE) tmp[is.na(tmp[, "wik"]), "wik"] <- FALSE index <- as.logical(tmp[, "wik"]) tmp <- tmp[, c("wij", "wjk")] output <- data.frame( numerator = rep(0, length(measure)), denominator = 0, coefficient = 0) for (i in 1:length(measure)) { if (measure[i] == "am") { tvalues <- rowSums(tmp) } else if (measure[i] == "gm") { tvalues <- sqrt(tmp[, "wij"] * tmp[, "wjk"]) } else if (measure[i] == "ma") { tvalues <- pmin.int(tmp[, "wij"], tmp[, "wjk"]) } else if (measure[i] == "mi") { tvalues <- pmax.int(tmp[, "wij"], tmp[, "wjk"]) } else if (measure[i] == "bi") { tvalues <- rep(1, nrow(tmp)) } else { stop("measure incorrectly specified") } output[i,1] <- sum(tvalues[index]) output[i,2] <- sum(tvalues) output[i,3] <- output[i,1]/output[i,2] } rownames(output) <- measure return(output) } # Get results of new function clustering_w_ND(net, measure=c("bi","am","gm","ma","mi"))]]>

Hi Naris,

Burt’s constraint metric is created for directed networks (see Burt, 1992, chapter 2); however, this metric or any local clustering coefficient becomes irrelevant if you have a complete network. You may want to set a cut-off and remove ties below this.

Best,

Tore

Hi Barbara,

There isn’t one, but there is a trick for the degree-function (for closeness and betweenness, self-loops do not matter): add a sink node as the degree function is local. See the code below.

Good luck,

Tore

# Load tnet library(tnet) # Generate random net net <- rg_w(n=5, arcs=0.2) # Add self-loops with a weight equal to node id net <- rbind( net, data.frame(i=1:5, j=1:5, w=1:5)) net <- net[order(net[,1], net[,2]),] # So the code for you would be: # Find the largest node id and add 1 sinkNode <- max(c(net[,"i"],net[,"j"]))+1 # Copy network netSinkNode <- net # Redirect receivers of self-loops to new node (replace "j" with "i" if in-degree) netSinkNode[netSinkNode[,"i"]==netSinkNode[,"j"],"j"] <- sinkNode # Compute degree out <- degree_w(netSinkNode, measure=c("degree","output","alpha"), alpha=0.5) # Remove net node out <- out[out[,"node"]!=sinkNode,]]]>

Thank you so much for the comments. I was also trying to use Burt’s c as a proxy of local clustering of trade. Yet, there are still two issues. First, in Burt’s conceptualization, the network seems undirected as well. So it might be problematic to use it in the case of bilateral trade. Second, the trade network generally is a complete network. So there is few, if any, structural holes in the network.

Recently, I’ve read an article on the subject. How do you think about their approach? Thank you so much!

McAssey, Michael P., and Fetsje Bijma. forthcoming. “A Clustering Coefficient for Complete Weighted Networks.” Network Science

]]>Hi,

Is there an option to disable this behavior? I.e. to preserve and count self-loops in your “alpha” measure?

Thanks

]]>