Skip to main content

Practical and statistical social network analysis tools for Python.

Project description

relationalstats

A practical Python toolkit for applied and statistical social network analysis, with research-grade documentation and transparent methodological boundaries.

relationalstats provides Python APIs for statistical network analysis workflows inspired by R sna, ergm, tergm / stergm, and linkprediction, while remaining explicit about what is equivalent, approximate, experimental, or planned.

What is included

Area Status
Link prediction Initial core implemented
QAPLogit Initial core implemented
ERGM Initial dyadic-logistic approximation
STERGM Initial separable dyadic-logistic approximation
R validation Placeholders and roadmap; fixtures pending

Installation for local development

python3.10 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -e ".[dev,test]"

Optional extras:

python -m pip install -e ".[docs]"
python -m pip install -e ".[notebooks,plot]"
python -m pip install -e ".[ml]"
python -m pip install -e ".[r]"

Quick usage

Link prediction

import networkx as nx
from relationalstats.linkprediction import ProxFun, proxfun_full

G = nx.path_graph(3)

scores = proxfun_full(
    G,
    pairs=[(0, 2)],
    metrics=["common_neighbors", "jaccard", "adamic_adar"],
)

result = ProxFun(metrics=["jaccard", "adamic_adar"]).fit(G)
result.to_dataframe()

QAPLogit

from relationalstats.datasets import make_qap_toy_data
from relationalstats.qap import QAPLogit

y, x_matrices = make_qap_toy_data()

result = QAPLogit(
    n_permutations=99,
    random_state=42,
    backend="statsmodels",
).fit(y, x_matrices)

result.to_dataframe()

ERGM approximation

from relationalstats.datasets import make_florentine_like_graph
from relationalstats.ergm import ERGM

G = make_florentine_like_graph()

result = ERGM(
    terms=["edges", "common_neighbors", "degree1", "gwesp", "nodematch:faction"],
    backend="sklearn",
    random_state=42,
).fit(G)

result.to_dataframe()
result.gof(n_sim=100, seed=123)

STERGM approximation

from relationalstats.datasets import make_stergm_temporal_toy
from relationalstats.stergm import STERGM

G1, G2 = make_stergm_temporal_toy()

result = STERGM(
    formation_terms=["edges", "common_neighbors", "degree1", "gwesp"],
    dissolution_terms=["edges", "common_neighbors", "degree1", "gwesp"],
    backend="sklearn",
    random_state=42,
).fit(G1, G2)

result.to_dataframe()
result.simulate(seed=123)

Documentation map

Examples

Run examples:

python examples/linkprediction/proxfun_feature_pipeline.py
python examples/qap/qap_logit_toy.py
python examples/qap/qap_logit_backend_comparison.py
python examples/ergm/ergm_florentine_like.py
python examples/stergm/stergm_temporal_toy.py

Repository structure

relationalstats/
├── docs/
│   ├── README.md
│   ├── ergm/
│   ├── linkprediction/
│   ├── methodology/
│   ├── qap/
│   └── stergm/
├── examples/
│   ├── README.md
│   ├── ergm/
│   ├── linkprediction/
│   ├── qap/
│   └── stergm/
├── notebooks/
│   └── README.md
├── scripts/
├── src/
│   └── relationalstats/
│       ├── datasets/
│       ├── ergm/
│       ├── linkprediction/
│       ├── modules/
│       ├── qap/
│       └── stergm/
├── tests/
│   ├── unit/
│   └── validation_against_r/
├── CHANGELOG.md
├── CONTRIBUTING.md
├── LICENSE
├── pyproject.toml
└── README.md

Running tests

source .venv/bin/activate
pytest -q

Focused test groups:

pytest tests/unit/test_linkprediction.py tests/unit/test_linkprediction_manual_graphs.py -q
pytest tests/unit/test_qap.py tests/unit/test_qap_permutation.py -q
pytest tests/unit/test_ergm_statistics.py tests/unit/test_ergm_gof.py -q
pytest tests/unit/test_stergm.py -q

Build and distribution validation

source .venv/bin/activate
rm -rf dist build *.egg-info
python -m pip install build twine
python -m build
python -m twine check "dist/*"
ls -lh dist/

Release flow

feature/* -> develop -> release/vX.Y.Z -> main -> tag vX.Y.Z -> PyPI

Pre-release versions should follow PEP 440:

0.1.0a1
0.1.0b1
0.1.0rc1
0.1.0

Methodological transparency

Current ERGM and STERGM implementations are dyadic-logistic approximations, not full MCMC-MLE implementations equivalent to R ergm, tergm, or stergm.

Validation against R

Planned validation fixtures include:

  • sna::netlogit for QAP-style logistic models;
  • linkprediction::proxfun for link prediction metrics;
  • ergm and network for selected network statistics;
  • tergm / stergm for temporal dyad construction where feasible.

Academic and private material policy

Solved academic notebooks, private experiments, raw course material, and non-public validation files should not be committed to the public repository.

Author

License

The source code in this repository is distributed under the MIT License. See LICENSE for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

relationalstats-0.1.0a1.tar.gz (53.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

relationalstats-0.1.0a1-py3-none-any.whl (36.3 kB view details)

Uploaded Python 3

File details

Details for the file relationalstats-0.1.0a1.tar.gz.

File metadata

  • Download URL: relationalstats-0.1.0a1.tar.gz
  • Upload date:
  • Size: 53.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for relationalstats-0.1.0a1.tar.gz
Algorithm Hash digest
SHA256 efb6ec1b69aa9a09d08235a07abc3dd05ca7d9a09aec609ea9c0c49e57c779a5
MD5 cada60838caab4ebda34344deafe720d
BLAKE2b-256 0f6cecbc59187c565c9923c50a0a1070fdc3e1fbc28e9c71c99d21c1f51e1fc2

See more details on using hashes here.

Provenance

The following attestation bundles were made for relationalstats-0.1.0a1.tar.gz:

Publisher: release.yml on HubertRonald/relationalstats

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file relationalstats-0.1.0a1-py3-none-any.whl.

File metadata

File hashes

Hashes for relationalstats-0.1.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 2edaeb8d2409b36c0e81bc0abc554f9743854e29ccb772ebdaeaa4a85f350473
MD5 8ea1a2fb172fff4fdfd451e6ec8491e0
BLAKE2b-256 ad2fc7a5406d8692936b92b0ddc0f9f1d477f79ffc24cebea88fab3c5336a4a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for relationalstats-0.1.0a1-py3-none-any.whl:

Publisher: release.yml on HubertRonald/relationalstats

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page