Roadmap

Introduction

Motivation

  • Standard GLMs (lm, glm) assume independent units:
    • Attributes (X_i, Y_i) of unit i are unaffected by unit j
  • Problem: Violated in connected population because of spillover and contagion!
  • Solution: A regression framework for dependent attributes (\mathbf{X}, \mathbf{Y}) and network connections \mathbf{Z} implemented in R Package iglm

Publications

Software Paper

Available on ArXiv (describing the iglm package):

Theory Paper

Published in the Journal of the American Statistical Association:

Advantages of R Package iglm

  • Comprehensive: Binary, count, and real-valued attributes \mathbf{X}, \mathbf{Y} & network connections \mathbf{Z}
  • Interpretable: Extension of standard GLMs with micro-behavioral foundation
  • Local Dependence: Neighborhoods \mathcal{N}_i to control dependencies
  • Scalable: Convex optimization via blockwise optimization
  • Guarantees: Error of O(N) weights decays at rate \sqrt{\log N / N}

Architecture & Setup

install.packages("iglm")
  • R6 class architecture (Chang, 2025):
    • iglm manages formula, sampler, and execution
    • iglm.data manages variables
  • Back-end implemented in C++ for high-performance computing

R6 Classes in R

Standard R (e.g., ergm)

Apply external functions to data/objects.

  • Syntax: Pass the object as an argument:

    # Fit the model:
    fit <- ergm(nw ~ edges + mutual)
    # Run external functions:
    summary(fit)
    sims <- simulate(fit, nsim = 10)
  • Copy-on-Modify: Modifying settings or data copies the entire object in memory

R6 Classes (e.g., iglm)

Data and functions live together in the object.

  • Syntax: Call functions/methods on the object:

    model <- iglm(nw ~ edges + mutual)
    model$estimate()  # Fits in-place
    model$simulate()  # Simulates in-place
  • In-Place Modification: Modifying the object in-place without copy overhead:

    model$set_control(max_it = 300)

Data Representation

Data Structure in iglm.data

  • Predictors \mathbf{X} = (X_i): binary, count, or real; fixed or random
  • Outcomes \mathbf{Y} = (Y_i): binary, count, or real
  • Connections \mathbf{Z} = (Z_{i,j}): binary Z_{i,j} \in \{0, 1\}, directed or undirected
  • Neighborhoods \mathcal{N}_i (exogenous): Overlap indicated by c_{i,j} = \mathbb{I}(\mathcal{N}_i \cap \mathcal{N}_j \neq \emptyset)

Running Example: Hate Speech on X

Is there a spillover effect from interacting with Republican politicians to employing offensive language in online communications?

  • Dataset: N = 495 state legislators across 6 states from Kim et al. (2022)
  • Outcome Y_i: Use of hate speech (1 = Yes, 0 = No)
  • Predictor X_i: Party affiliation (1 = Republican, 0 = Other) [fixed]
  • Network Z_{i,j}: Directed mention/repost network on X (Twitter)
  • Covariates: Gender (v_{i,1}), Race (v_{i,2}), and State (v_{i,3})

Running Example: Hate Speech on X

Is there a spillover effect from interacting with Republican politicians to employing offensive language in online communications?

Data Representation: iglm.data

  • Load the pre-packaged dataset directly:
data("state_twitter")
data.object <- state_twitter$iglm.data$clone()
  • Exogenous Covariates gender_attribute, white_attribute, match_gender, match_race, match_state are available via package
Show code
# Extracting covariates from state_twitter object
match_gender     <- state_twitter$match_gender
match_race       <- state_twitter$match_race
match_state      <- state_twitter$match_state
white_attribute  <- state_twitter$white_attribute
gender_attribute <- state_twitter$gender_attribute
  • Import from raw files (vectors or matrices)
Show code
z_network <- read.csv("z_network.csv")
x_attribute <- read.csv("x_attribute.csv")
y_attribute <- read.csv("y_attribute.csv")
neighborhood <- as.matrix(read.csv("neighborhood.csv"))

data.object <- iglm.data(
  x_attribute = x_attribute,  type_x = "binomial",
  y_attribute = y_attribute,  type_y = "binomial",
  z_network = z_network,      directed = TRUE,
  neighborhood = neighborhood
)

Descriptive Analysis: Data Object Summary

data.object
iglm.data object
  units                       : 495
  directed                    : TRUE
  edges (fixed = FALSE)       : 9218
  neighborhood edges          : 24398

Attribute summaries
  x_attribute (fixed = TRUE)  : binomial 1s=195, 0s=300, P(1)=0.394
  y_attribute                 : binomial 1s=204, 0s=291, P(1)=0.412

Descriptive Analysis: Visualizing the Network

  • The package provides a plotting function based on igraph
  • Node size \rightarrow predictor variables \mathbf{X}
  • Node colors \rightarrow outcome variables \mathbf{Y}
  • Grey lines \rightarrow directed connections \mathbf{Z}
  • Orange lines \rightarrow overlapping neighborhoods \mathcal{N}_i \cap \mathcal{N}_j \neq \emptyset
set.seed(123)
data.object$plot(
  edge.width = 0.5, 
  edge.arrow.size = 0.2, 
  legend_size = 0.5, 
  legend_size_n_levels = 2
)

Descriptive Analysis: Different Statistics

# Plot spillover degree distribution
data.object$spillover_degree_distribution()
  • Spillover degree distribution: The degree in the subnetwork of connections that can enable spillover (i.e., connections where c_{i,j} x_i y_j = 1 or c_{i,j} x_j y_i = 1)

# Plot outcome distribution
data.object$y_distribution()
  • Outcome distribution (y_distribution): The empirical distribution of the node-level outcomes Y (density or bar plot depending on the outcome type)

# Plot traditional degree distribution
data.object$degree_distribution()
  • Degree distribution: Distribution of number of outgoing and incoming connections

# Plot geodesic distances distribution
data.object$geodesic_distances_distribution()
  • Geodesic distance distribution: The distribution of shortest path distances (geodesic distances) between all pairs of connected actors in the symmetrized network

# Plot edgewise shared partner distribution
data.object$edgewise_shared_partner_distribution()
  • Edgewise shared partner distribution: The distribution of edgewise shared partner (ESP) counts (i.e., the number of mutual neighbors that two connected actors share in the network)