1

Problem Description:

I am attempting to perform temporal network analysis using R, specifically utilizing the temporal network tools provided by statnet: networkDynamic and ndtv. The purpose is to observe the changes that occur in a network over time. However, I am facing an error when trying to execute the networkDynamic function.

Here is the relevant information:

language R
version.string R version 4.3.1 (2023-06-16 ucrt) nickname Beagle Scouts System

Data:

test_spells <- data.frame(
  onset = c(58, 65, 74, 77, 52, 55, 57, 1, 6, 17, 20, 22, 46, 74, 52, 57, 58, 84, 60, 71, 61),
  terminus = c(63, 66, 74, 77, 52, 55, 60, 4, 15, 18, 20, 44, 67, 78, 54, 58, 62, 84, 63, 71, 61),
  idTail = c(248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 29, 29, 29, 29, 29, 29, 29),
  idHead = c(28, 28, 28, 28, 29, 29, 29, 76, 76, 76, 76, 76, 76, 76, 248, 248, 28, 28, 3, 3, 56)
)

test_el <- data.frame(
  idTail = c(29, 29, 29, 29, 248, 248, 248),
  idHead = c(3, 28, 56, 248, 28, 29, 76),
  weight = c(2, 2, 1, 2, 4, 3, 7),
  edge.id = c(1, 2, 3, 4, 5, 6, 7)
)

Code:

net <- network(x = test_el)
net_dyn <- networkDynamic(base.net = net, edge.spells = test_spells)

Error Message:

Error in networkDynamic(base.net = net, edge.spells = test_spells) : base.net network size is smaller than size implied by vertex.ids in vertex or edge argument

Network plot

plot.network(net,label = network.vertex.names(net))

network

Could someone please help me understand why I am getting this error message and how to resolve this issue? Thank you in advance!

JHJH
  • 47
  • 6

1 Answers1

0

Your code does not work because net will has only 6 vertices instead of 248 (?) as the edge list contains only 6 unique vertex IDs in the first two columns. I suspect you were expecting network()to work like as.network() which creates a network of the order equal to the maximal value in the edge list (see #2 below). Two approaches to achieve your goal that essentially ensure that net has the proper number of vertices:

1

# 1
net <- network.initialize(248) |>
  add.edges(
    tail = test_el$idTail, 
    head = test_el$idHead,
    names.eval = rep(list(list("weight", "edge.id")), nrow(test_el)),
    vals.eval = lapply(1:nrow(test_el), function(r) test_el[r, c("weight", "edge.id"), drop=FALSE])
  )
net_dyn <- networkDynamic(base.net = net, edge.spells = test_spells)

2

net <- as.network(data.matrix(test_el[,1:2]))
net %e% "weight" <- test_el$weight
net %e% "edge.id" <- test_el$edge.id
net_dyn <- networkDynamic(base.net = net, edge.spells = test_spells)
Michał
  • 2,755
  • 1
  • 17
  • 20