graphchi_ERSBM {GoodFitSBM}R Documentation

Computation of the chi-square test statistic for goodness-of-fit, under ERSBM

Description

graphchi_ERSBM obtains the value of the chi-square test statistic required for the goodness-of-fit of a ERSBM (Karwa et al. (2023))

Usage

graphchi_ERSBM(G, C, p_mle)

Arguments

G

an igraph object which is an undirected graph with no self loop

C

a positive integer vector of size n for block assignments of each node; from 1 to K (no of blocks)

p_mle

a matrix with the MLE estimates of the edge probabilities

Value

A numeric value

teststat_val

The value of the chi-square test statistic

See Also

goftest_ERSBM() performs the goodness-of-fit test for the ERSBM, where the values of the chi-square test statistics are required

Examples

RNGkind(sample.kind = "Rounding")
set.seed(1729)

# We model a network with 3 even classes
n1 = 2
n2 = 2
n3 = 2

# Generating block assignments for each of the nodes
n = n1 + n2 + n3
class = rep(c(1, 2, 3), c(n1, n2, n3))

# Generating the adjacency matrix of the network
# Generate the matrix of connection probabilities
cmat = matrix(
  c(
    0.8, 0.5, 0.5,
    0.5, 0.8, 0.5,
    0.5, 0.5, 0.8
  ),
  ncol = 3,
  byrow = TRUE
)
pmat = cmat / n

# Creating the n x n adjacency matrix
adj <- matrix(0, n, n)
for (i in 2:n) {
  for (j in 1:(i - 1)) {
    p = pmat[class[i], class[j]] # We find the probability of connection with the weights
    adj[i, j] = rbinom(1, 1, p) # We include the edge with probability p
  }
}

adjsymm = adj + t(adj)

# graph from the adjacency matrix
G = igraph::graph_from_adjacency_matrix(adjsymm, mode = "undirected", weighted = NULL)

# mle of the edge probabilities
p.hat = get_mle_ERSBM(G, class)

# chi-square test statistic values
graphchi_ERSBM(G, class, p.hat)

[Package GoodFitSBM version 0.0.1 Index]