# Network graph: hypothesis test that degree distribution is becoming more equitable

I'm playing around with network graphs and am wondering how to show that there is:

1. a statistically significant difference in in-degree distribution between nodes for 2 time periods
2. the in-degree distribution is more equally dispersed among nodes at time 2

Now let's say I have a classroom of students and I asked them to name the 3 kids who they thought was getting the most negative attention from other students. Let's say three kids (J, K, and L) were getting the most negative attention (we'll say they're being bullied).

Now we conduct a session (treatment) and now conduct a follow up question to the classroom again asking the three students that were receiving the most negative attention.

Here I plotted that out with R as a network graph. You can see from the weighting I obviously made this the 'ideal' situation that I have described and after the treatment the vertices are more equally distributed.

How can I show a statistically significant: (a) change in the distribution of in-degrees (incoming edges) and (b) the distribution of in-degrees (incoming edges) is more equal?

library(igraph); library(reshape2)

weights_1 <- c(.01, .01, .01, .01, .01, .05, .05, .05, .05, .25, .25, .25)
weights_2 <- rep(1/11, 12)

selects <- function(p, n = 12) {
melt(data.frame(from = LETTERS[1:n],
do.call(rbind, lapply(1:n, function(i) {
sample(LETTERS[1:n][-i], 3, FALSE, prob = p[-i])
}))),
id="from", value.name="to",
variable.name = "choice.n"
)[, c(1, 3, 2)]
}

set.seed(100)
time_1 <- selects(weights_1)
t1 <- graph.data.frame(time_1)

set.seed(100)
time_2 <- selects(weights_2)
t2 <- graph.data.frame(time_2)

E(t1)$arrow.size <- .6 E(t2)$arrow.size <- .6

par(mfrow=c(1,2))
plot(t1, layout=layout.circle); mtext("Time 1")
plot(t2, layout=layout.circle); mtext("Time 2")


EDIT It occurs to me that it may be easier to help if the Boolean matrices and adjacency matrices are already created:

Here it is as a viewable format:

$Boolean_time1 A B C D E F G H I J K L A 0 0 0 0 0 0 0 0 0 0 0 0 B 0 0 0 0 0 0 0 0 0 0 0 0 C 0 0 0 0 0 0 0 0 0 0 0 0 D 0 0 0 0 0 0 0 0 0 0 0 0 E 0 0 0 0 0 0 0 0 0 0 1 1 F 0 0 1 0 0 0 0 0 0 0 0 1 G 1 0 0 0 0 0 0 0 0 1 0 1 H 0 0 0 0 1 0 0 0 1 0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0 0 0
J 0 0 1 1 1 0 2 1 0 4 1 1
K 1 0 1 0 0 3 2 2 0 1 5 0
L 0 0 1 1 0 0 1 0 0 1 0 2


As an easy to grab R format:

 dats <- structure(list(Boolean_time1 = structure(list(A = c(0L, 0L, 0L,
0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 1L), B = c(0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 1L, 1L, 1L), C = c(0L, 0L, 0L, 0L, 0L, 1L, 0L,
0L, 0L, 0L, 1L, 1L), D = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L,
1L, 1L, 0L), E = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L,
1L), F = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L), G = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L), H = c(0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 0L), I = c(0L, 0L, 0L, 0L, 0L,
0L, 0L, 1L, 0L, 0L, 1L, 1L), J = c(0L, 0L, 0L, 0L, 0L, 0L, 1L,
0L, 0L, 0L, 1L, 1L), K = c(0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L,
1L, 0L, 1L), L = c(0L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 0L,
0L)), .Names = c("A", "B", "C", "D", "E", "F", "G", "H", "I",
"J", "K", "L"), row.names = c("A", "B", "C", "D", "E", "F", "G",
"H", "I", "J", "K", "L"), class = "data.frame"), Boolean_time2 = structure(list(
A = c(0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 1L, 0L, 0L, 0L), B = c(0L,
0L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 0L), C = c(0L, 0L,
0L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 1L, 0L), D = c(0L, 0L, 1L,
0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L), E = c(0L, 0L, 0L, 0L,
0L, 1L, 1L, 0L, 0L, 0L, 1L, 0L), F = c(0L, 0L, 0L, 1L, 0L,
0L, 1L, 0L, 0L, 1L, 0L, 0L), G = c(0L, 0L, 0L, 0L, 1L, 0L,
0L, 1L, 0L, 1L, 0L, 0L), H = c(0L, 0L, 0L, 0L, 0L, 0L, 1L,
0L, 0L, 1L, 1L, 0L), I = c(0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L,
0L, 0L, 1L, 0L), J = c(0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L,
0L, 0L, 1L), K = c(1L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 0L,
0L, 0L), L = c(1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L,
0L)), .Names = c("A", "B", "C", "D", "E", "F", "G", "H",
"I", "J", "K", "L"), row.names = c("A", "B", "C", "D", "E", "F",
"G", "H", "I", "J", "K", "L"), class = "data.frame"), adjmat_time1 = structure(c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0,
1, 2, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 3, 0, 0, 1, 1, 2, 0,
0, 0, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2,
2, 0, 0, 0, 0, 0, 1, 0, 1, 0, 2, 7, 5, 5, 0, 0, 0, 0, 0, 1, 1,
2, 2, 5, 9, 7, 0, 0, 0, 0, 1, 1, 2, 2, 0, 5, 7, 9), .Dim = c(12L,
12L), .Dimnames = list(c("A", "B", "C", "D", "E", "F", "G", "H",
"I", "J", "K", "L"), c("A", "B", "C", "D", "E", "F", "G", "H",
"I", "J", "K", "L"))), adjmat_time2 = structure(c(2, 0, 0, 0,
1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 3, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 2, 0, 0, 2, 0, 0, 1,
0, 1, 1, 0, 0, 0, 3, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 4, 1,
1, 1, 0, 3, 0, 1, 0, 0, 2, 1, 1, 5, 0, 0, 2, 2, 1, 1, 0, 1, 0,
1, 1, 0, 4, 1, 1, 2, 0, 0, 0, 1, 0, 1, 1, 0, 1, 2, 0, 0, 0, 0,
0, 1, 1, 1, 0, 2, 1, 0, 4, 1, 1, 1, 0, 1, 0, 0, 3, 2, 2, 0, 1,
5, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 2), .Dim = c(12L, 12L), .Dimnames = list(
c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K",
"L"), c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
"K", "L")))), .Names = c("Boolean_time1", "Boolean_time2",