# Using `ergm.sign` to analyse the signed Read’s Highland Tribes dataset

#### Marc Schalberger

    ## Warning: package 'ergm' was built under R version 4.4.3

    ## Loading required package: network

    ##
    ## 'network' 1.19.0 (2024-12-08), part of the Statnet Project
    ## * 'news(package="network")' for changes since last version
    ## * 'citation("network")' for citation information
    ## * 'https://statnet.org' for help, support, and other information

    ##
    ## 'ergm' 4.11.0 (2025-12-22), part of the Statnet Project
    ## * 'news(package="ergm")' for changes since last version
    ## * 'citation("ergm")' for citation information
    ## * 'https://statnet.org' for help, support, and other information

    ## 'ergm' 4 is a major update that introduces some backwards-incompatible
    ## changes. Please type 'news(package="ergm")' for a list of major
    ## changes.

    ##
    ## 'ergm.multi' 0.3.0 (2025-06-14), part of the Statnet Project
    ## * 'news(package="ergm.multi")' for changes since last version
    ## * 'citation("ergm.multi")' for citation information
    ## * 'https://statnet.org' for help, support, and other information

    ##
    ## Attaching package: 'ergm.multi'

    ## The following object is masked from 'package:ergm':
    ##
    ##     snctrl

    library(ergm.sign)

# Obtaining data

The highland tribes dataset from Read (1954) is included in the `ergm.sign` package:

    data("tribes")

This gives us a multilayer network construct with a positive and a negative layer encoding the allied and hostile relationships between the tribes.

# Desctiptive statistics

The summary `summary` function returns a matrix with the most important descriptive statistics for the signed network:

    summary(tribes)

    ## Network Attributes:

    ##       Directed Loops Nodes Edges Edges+ Edges- Triads +++ --- ++- +-- Density
    ## edges    FALSE FALSE    16    58     29     29     68  19   7   2  40    0.48

If we would like to get other descriptive statistics using the `summary_formula` function:

    summary(tribes ~ edges + Pos(~ edges) + Neg(~ edges))

    ##     edges Pos~edges Neg~edges
    ##        58        29        29

# Plotting the network

It is also possible to plot the signed network using the `plot` function. Which requires the `UnLayer` function that turns the multilayer network into a single layer network:

    tribes_sgl <- UnLayer(tribes, color_pos = "green3", color_neg = "red3")
    plot(tribes_sgl, edge.col = "col", label = "vertex.names")

# Fitting a model

Just like in the unsigned case, we can call the `ergm` function to fit a model to the signed network. The `ergm` function requires a formula that specifies the model to be fitted. In addition to the normal ergm terms we can also use the `Pos` and the `Neg` function to specify terms that only apply to the positive or negative layer of the network.

    fit <- ergm(tribes ~ Pos(~ edges) + Neg(~ edges))
    summary(fit)

    ## Call:
    ## ergm(formula = tribes ~ Pos(~edges) + Neg(~edges))
    ##
    ## Monte Carlo Maximum Likelihood Results:
    ##
    ##           Estimate Std. Error MCMC % z value Pr(>|z|)
    ## Pos~edges  -0.7827     0.2052      0  -3.815 0.000136 ***
    ## Neg~edges  -0.7819     0.2433      0  -3.214 0.001309 **
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ##
    ##      Null Deviance:   0.00  on 240  degrees of freedom
    ##  Residual Deviance: -17.17  on 238  degrees of freedom
    ##
    ## Note that the null model likelihood and deviance are defined to be 0. This means that all likelihood-based inference (LRT, Analysis of
    ## Deviance, AIC, BIC, etc.) is only valid between models with the same reference distribution and constraints.
    ##
    ## AIC: -13.17  BIC: -6.21  (Smaller is better. MC Std. Err. = 0.3932)

Triadic effects are of particular interest in the context of signed networks.

    triad_fit <- ergm(tribes ~ gwese(0.5, fixed = TRUE, base = "+") + gwesf(0.5, fixed = TRUE, base = "+"))
    summary(triad_fit)

    ## Call:
    ## ergm(formula = tribes ~ gwese(0.5, fixed = TRUE, base = "+") +
    ##     gwesf(0.5, fixed = TRUE, base = "+"))
    ##
    ## Monte Carlo Maximum Likelihood Results:
    ##
    ##              Estimate Std. Error MCMC % z value Pr(>|z|)
    ## gwese(+).0.5 -0.35092    0.14821      0  -2.368   0.0179 *
    ## gwesf(+).0.5 -0.02680    0.07943      0  -0.337   0.7358
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ##
    ##      Null Deviance:  0.000  on 240  degrees of freedom
    ##  Residual Deviance: -5.474  on 238  degrees of freedom
    ##
    ## Note that the null model likelihood and deviance are defined to be 0. This means that all likelihood-based inference (LRT, Analysis of
    ## Deviance, AIC, BIC, etc.) is only valid between models with the same reference distribution and constraints.
    ##
    ## AIC: -1.474  BIC: 5.488  (Smaller is better. MC Std. Err. = 0.2907)

Here, the `gwese` (geometrically weighted edgewise shared enemies) term models enemy of my enemy is my friend configuration and the `gwesf` (geometrically weighted edgewise shared friends) term models friend of a friend is a friend configuration.

# Goodness of fit

In order to assess the goodness of fit of the model we can use the `GoF` function, which compares the observed network statistics to the statistics of simulated networks. The `nsim` argument specifies the number of simulations to be performed. For example, to perform 20 simulations we can use the following code:

    GoF(fit, nsim = 20)

# References

Read, Kenneth E. 1954. “Cultures of the Central Highlands, New Guinea.” Southwestern Journal of Anthropology 10 (1): 1–43.