blob: d96bd812fc58ea89af86117ec84fe2226d423333 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
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[tvs<tu]
if (length(tvs)>0){
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)
|