vics = vic_ids graph = lcc n.infections = length(vics) vic.neighbors = rep(0,n.infections) for (i in 1:n.infections){ u = vics[i] nbhd = unlist(neighborhood(graph, nodes=u, order=3)) nbhd = intersect(vic_ids,nbhd) vic.neighbors[i] = sum(nbhd %in% vics) } n.infections = length(vics) vic.time = rep(0,n.infections) for (i in 1:n.infections){ if (i%%1000==0) print(i) u = vics[i] nbhd = unlist(neighborhood(graph, nodes=u, order=1)) nbhd = intersect(vic_ids,nbhd) nbhd = setdiff(nbhd,u) tu = as.numeric(V(graph)$vic_date[u]) tvs = as.numeric(V(graph)$vic_date[nbhd]) tvs = tvs[tvs0){ vic.time[i] = min(tu-tvs) } } vic.time = vic.time[vic.time>0] mean(vic.time) median(vic.time) mean(vic.time<100) sum(vic.time>0)