1

A subset of my data for a temporal network are as below:

edge <- data.frame(onset = c(1968, 1968, 2007),
               terminus = c(1968, 1968, 2007),
               id_from = c(1, 1, 2),
               id_to = c(3, 2, 4),
               weight = c(1, 3, 2))

vert <- data.frame(onset = c(1968, 1968, 1980, 1978),
               terminus = c(2017, 2017, 2017, 2017),
               vertex_id = c(1, 2, 3, 4),
               abb.name = c("UK", "US", "Germany", "Pakistan"))

# Create networkDynamic object
netd <- networkDynamic(vertex.spells = vert[,c(1,2,3,4)],
                   edge.spells = edge[,c(1,2,3,4,5)],
                   create.TEAs = TRUE,
                   edge.TEA.names = "weight")

vert$abb.name <- as.character(vert$abb.name)

# Set vertex attributes
set.vertex.attribute(netd, "abb.name", as.vector(vert$abb.name))
network.vertex.names(netd)<-vert$abb.name

# Collapse network to look at 1968 network
net68 <- network.collapse(netd,
                      at = 1968, 
                      rm.time.info = FALSE,
                      rule = "latest")
# Get centrality score
degree(net68)

However, this returns centrality scores that do not take the weights into account.

[1] 1 1

How can I make sure that networkDynamic takes into consideration that (1) weights per year are significant so it doesn't calculate multiple ties between the same two countries as one edge in the aggregate network, (2) the weights get counted in the centrality scores properly, and (3) get a degree() output that includes country name? Ideally, I'd like to get centrality scores for each country in each slice of the network from 1968 to 2017.

1984
  • 41
  • 3

2 Answers2

1

It seems to be a bug, or a lack of documentation. Thanks for reporting. This should work for now:

degree(as.edgelist.sna(net68, "weight"))
Michał
  • 2,755
  • 1
  • 17
  • 20
  • 1
    to give more background `degree` in the `sna` package basically expects a matrix as an input, so you have to tell how the `network` object should be converted: should it just count edges? which attribute should be used for edge weights? so this also works with the same result: `degree(as.matrix(net68,attrname='weight'))` – skyebend May 16 '19 at 04:39
0

To partially answer your part (3) the tsna package provides the function tSnaStats() as way to apply metrics from the sna package at multiple time points over a networkDynamic object and produce the result as a timeseries

> library(tsna)
> tSnaStats(netd,'degree')
Time Series:
Start = 1968 
End = 2017 
Frequency = 1 
     UK US Germany Pakistan
1968  1  1       1        1
1969  0  0       0        0
1970  0  0       0        0
1971  0  0       0        0
1972  0  0       0        0
1973  0  0       0        0
1974  0  0       0        0
...
2007  0  1       0        1
2008  0  0       0        0
2009  0  0       0        0
2010  0  0       0        0
2011  0  0       0        0
2012  0  0       0        0
2013  0  0       0        0
2014  0  0       0        0
2015  0  0       0        0
2016  0  0       0        0

Unfortunately, although tSnaStats() can pass arguments to the degree() function, I don't see an easy way to tell it to use the weight attribute when creating the matrix for each time point.

skyebend
  • 1,079
  • 6
  • 19