kaijagahm / toyModel

Modeling the impact of multiple mortality on vulture social networks. Started in Spring 2022 for Jamie Lloyd-Smith's C219B Ecological Modeling course.
2 stars 0 forks source link

Connectivity (mean distance) verification #8

Closed kaijagahm closed 2 years ago

kaijagahm commented 2 years ago

Double check that mean_distance ignores singletons, which would be why it decreases when an individual is lost.

kaijagahm commented 2 years ago

Indeed, mean_distance does seem to ignore singletons. Here is a reproducible example.

test1 <- matrix(data = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0), nrow = 4, ncol = 4)
g <- graph_from_adjacency_matrix(test1, mode = "undirected")
mean_distance(g)
> 1.33

This is consistent with there being three nodes included in the calculation, with pairwise distances 1, 1, and 2, respectively. 1.33 is NOT consistent with there being 4 nodes included, with pairwise distances 1, 1, 2, 0, 0, 0, respectively: that would yield 4/6 = 0.66, which != 1.33.

I tried removing another node, yielding two isolated nodes:

test2 <- matrix(data = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0), nrow = 4, ncol = 4)
g <- graph_from_adjacency_matrix(test2, mode = "undirected")
mean_distance(g)
> 1

In conclusion, it does indeed make sense that mean_distance decreases when an individual is lost, because losing the individual probably increases the number of isolated nodes in the graph.