Skip to content
Back to skills

Statnet

ASecurity

R statnet suite for network analysis. Use for statistical modeling of network data including ERGM.

  • 5 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added June 4, 2026
datagonodegit

Works with

  • cli

Security analysis

A100/100

Scanned June 4, 2026

npx -y skills add LeoLin990405/r-analytics-skill --skill statnet --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Statnet?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Statnet
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/leolin990405-statnet/badge)](https://www.skillsdirectory.com/skills/leolin990405-statnet)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: statnet
description: R statnet suite for network analysis. Use for statistical modeling of network data including ERGM.
---

# statnet

Statistical analysis of network data.

## Installation

```r
# Install statnet suite
install.packages("statnet")

# Load
library(statnet)
# Loads: network, sna, ergm, tergm, networkDynamic, etc.
```

## Network Descriptives (sna)

```r
library(sna)

# Centrality measures
degree(net)
degree(net, cmode = "indegree")
degree(net, cmode = "outdegree")

betweenness(net)
closeness(net)
evcent(net)  # Eigenvector centrality

# Network-level measures
gden(net)      # Density
grecip(net)    # Reciprocity
gtrans(net)    # Transitivity
centralization(net, degree)
```

## ERGM (Exponential Random Graph Models)

```r
library(ergm)

# Fit basic ERGM
fit <- ergm(net ~ edges)

# With structural terms
fit <- ergm(net ~ edges + mutual + triangle)

# With node attributes
fit <- ergm(net ~ edges + nodematch("gender") + nodecov("age"))

# With edge attributes
fit <- ergm(net ~ edges + edgecov(covariate_matrix))

# Summary
summary(fit)
```

## ERGM Terms

```r
# Structural terms
edges           # Number of edges
mutual          # Mutual ties (reciprocity)
triangle        # Triangles
gwesp(0.5)      # Geometrically weighted ESP
gwdegree(0.5)   # Geometrically weighted degree
kstar(2)        # 2-stars

# Attribute terms
nodematch("attr")      # Homophily
nodemix("attr")        # Mixing patterns
nodecov("attr")        # Node covariate (continuous)
nodefactor("attr")     # Node factor (categorical)
absdiff("attr")        # Absolute difference

# Dyadic terms
edgecov(matrix)        # Edge covariate
```

## ERGM Diagnostics

```r
# MCMC diagnostics
mcmc.diagnostics(fit)

# Goodness of fit
gof_result <- gof(fit)
plot(gof_result)

# Simulate from model
sim_nets <- simulate(fit, nsim = 100)
```

## TERGM (Temporal ERGM)

```r
library(tergm)

# Create network list
net_list <- list(net_t1, net_t2, net_t3)

# Fit STERGM (separable temporal ERGM)
fit <- stergm(
  net_list,
  formation = ~ edges + mutual,
  dissolution = ~ edges,
  estimate = "CMLE"
)

# Summary
summary(fit)
```

## Network Visualization (sna)

```r
# Basic plot
gplot(net)

# With attributes
gplot(net,
      vertex.col = net %v% "color",
      vertex.cex = degree(net) / max(degree(net)) * 3,
      edge.col = "gray",
      displaylabels = TRUE
)

# Layout algorithms
gplot(net, mode = "fruchtermanreingold")
gplot(net, mode = "kamadakawai")
gplot(net, mode = "circle")
gplot(net, mode = "mds")
```

## Community Detection

```r
# Equivalence clustering
eq <- equiv.clust(net)
plot(eq)

# Block modeling
bm <- blockmodel(net, eq, k = 3)
plot(bm)
```

## Network Comparison

```r
# QAP correlation
qap_result <- qaptest(list(net1, net2), gcor, g1 = 1, g2 = 2)
summary(qap_result)
plot(qap_result)

# Network correlation
gcor(net1, net2)

# Hamming distance
hdist(net1, net2)
```

## Simulation

```r
# Simulate from ERGM
sim <- simulate(fit, nsim = 100)

# Random graphs
rgraph(n = 10, m = 1, tprob = 0.3)  # Bernoulli
rgnm(n = 10, m = 20)                 # Fixed edges
```

## Latent Space Models

```r
library(latentnet)

# Fit latent space model
fit <- ergmm(net ~ euclidean(d = 2))

# With clustering
fit <- ergmm(net ~ euclidean(d = 2, G = 3))

# Plot
plot(fit)
```

## Network Regression

```r
# Network autocorrelation model
library(sna)

# QAP regression
netlm_result <- netlm(net, list(covariate1, covariate2), reps = 1000)
summary(netlm_result)

# Network logistic regression
netlogit_result <- netlogit(net, list(cov1, cov2), reps = 1000)
summary(netlogit_result)
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.