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
- Documentation index
- Link prediction
- QAP
- ERGM approximation
- STERGM approximation
- Equivalence vs approximation
- Reproducibility
- Roadmap
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::netlogitfor QAP-style logistic models;linkprediction::proxfunfor link prediction metrics;ergmandnetworkfor selected network statistics;tergm/stergmfor 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
- Hubert Ronald - Initial Work - HubertRonald
License
The source code in this repository is distributed under the MIT License. See LICENSE for more details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
efb6ec1b69aa9a09d08235a07abc3dd05ca7d9a09aec609ea9c0c49e57c779a5
|
|
| MD5 |
cada60838caab4ebda34344deafe720d
|
|
| BLAKE2b-256 |
0f6cecbc59187c565c9923c50a0a1070fdc3e1fbc28e9c71c99d21c1f51e1fc2
|
Provenance
The following attestation bundles were made for relationalstats-0.1.0a1.tar.gz:
Publisher:
release.yml on HubertRonald/relationalstats
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
relationalstats-0.1.0a1.tar.gz -
Subject digest:
efb6ec1b69aa9a09d08235a07abc3dd05ca7d9a09aec609ea9c0c49e57c779a5 - Sigstore transparency entry: 1885437192
- Sigstore integration time:
-
Permalink:
HubertRonald/relationalstats@8cea0d7fad80bea909e2aba4562e480b47f7da83 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/HubertRonald
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8cea0d7fad80bea909e2aba4562e480b47f7da83 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file relationalstats-0.1.0a1-py3-none-any.whl.
File metadata
- Download URL: relationalstats-0.1.0a1-py3-none-any.whl
- Upload date:
- Size: 36.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2edaeb8d2409b36c0e81bc0abc554f9743854e29ccb772ebdaeaa4a85f350473
|
|
| MD5 |
8ea1a2fb172fff4fdfd451e6ec8491e0
|
|
| BLAKE2b-256 |
ad2fc7a5406d8692936b92b0ddc0f9f1d477f79ffc24cebea88fab3c5336a4a4
|
Provenance
The following attestation bundles were made for relationalstats-0.1.0a1-py3-none-any.whl:
Publisher:
release.yml on HubertRonald/relationalstats
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
relationalstats-0.1.0a1-py3-none-any.whl -
Subject digest:
2edaeb8d2409b36c0e81bc0abc554f9743854e29ccb772ebdaeaa4a85f350473 - Sigstore transparency entry: 1885437212
- Sigstore integration time:
-
Permalink:
HubertRonald/relationalstats@8cea0d7fad80bea909e2aba4562e480b47f7da83 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/HubertRonald
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8cea0d7fad80bea909e2aba4562e480b47f7da83 -
Trigger Event:
workflow_dispatch
-
Statement type: