Skip to main content

A Python package for the econometric analysis of the dyadic network formation models with degree heterogeneity

Project description


Python 3.8+ PyPI Docs PyTorch

NetworkFm is a Python package for the econometric analysis of the dyadic network formation models with degree heterogeneity. The package accompanies the paper:

Yan, Zizhong; Li, Jingrong; Zhang, Yi (2026). Penalized Likelihood for Dyadic Network Formation Models with Degree Heterogeneity. (arXiv:2605.00771)

Quick links

What does NetworkFm do?

NetworkFm provides a single, unified interface for fitting several workhorse dyadic network formation models:

  1. Directed utility and mutual (reciprocity) utility (the main setting of the paper)
  2. Directed utility only (no mutual component), and
  3. Mutual utility only, which corresponds to undirected networks.

A key motivation for NetworkFm is that empirical network data are often sparse. In sparse networks, standard fixed-effects estimation routines can break down. Not only because of the classic incidental parameter problem, but also because estimation may be infeasible due to existence / separation–type issues. In practice, this can turn a seemingly standard application into “the optimizer never converges” or “some fixed effects are not identified,” even when the model is conceptually appropriate.

The package implements the likelihood correction proposed in Yan, Li, and Zhang (2026). This correction is designed to address both challenges at once:

  • it delivers bias reduction for common parameters in the presence of high-dimensional degree heterogeneity, and
  • it remains operational in sparse-network settings under the paper’s convex-hull feasibility condition, substantially enlarging the set of datasets for which estimation is practically usable.

In addition, once the likelihood correction is applied, NetworkFm provides debiased plug-in estimates of average partial effects (APEs), for continuous and discrete regressors.

Estimators included

  • Likelihood correction (Yan, Li, and Zhang, 2026)

    • Implements the paper’s likelihood-based adjustment for all three model classes above.
    • Addresses the incidental-parameter bias and the sparse network problem (the convex-hull condition).
    • Reports debiased APEs for continuous and discrete/finite-change effects.
  • Estimator-based correction (benchmarks / comparisons)

    • For directed + mutual utility: estimator-based correction following Yan, Li, and Zhang (2026).
    • For directed utility only: estimator-based correction following Yan et al. (2019).
    • For mutual utility only / undirected networks: estimator-based correction following Graham (2017).
  • Conditional likelihood method (benchmarks / comparisons)

    • Tetrad logit for undirected networks (Graham, 2017), via a vendored copy of netrics (Graham, 2016).
    • Quadruple logit for directed networks without mutual utility (Jochmans, 2018), via the bundled quadlogit package by Hu et al. (2026).
    • NetworkFm exposes these methods through the same networkfm.fit() interface and data conventions, so users can compare likelihood correction, estimator correction, and conditional likelihood without rewriting data pipelines.

Installation

  1. Installation via pip install (easiest and recommended)
pip install networkfm
  1. Install the development version via GitHub
git clone https://github.com/zizhongyan/networkfm.git
cd networkfm
pip install -e .
  1. Manual installation

Downloaded this Github source code as a ZIP file and unzipped it locally, run the following from the repository root:

cd /path/to/networkfm
pip install -e .

Quick start

import networkfm

res = networkfm.fit(
    G, # the network adjacency matrix
    X, Z, # covariates in directed and mutual utilities respectively
    directed=True, mutual=True,   # directed + mutual utility
    bc_method="likelihood", # likelihood correction
    algorithm="JML" 
)

print(res.paras)  # parameter estimates
print(res.se)     # standard errors
print(res.ape)    # average partial effects

Visit the project's documentation for tutorials, examples gallery, and API reference.

Dependencies

  • Python ≥ 3.8
  • PyTorch is required (CPU-only is fine). It is used for autograd.
  • The repository bundles (vendors) several research codes used as benchmarks:
    • ipt (Graham, 2016) for common logit routines,
    • netrics (Graham, 2016) for tetrad logit,
    • quadlogit the package Hu et al. (2025) based on the paper Jochmans (2018).

Citing NetworkFm

Please cite the paper and the software when using this package.

  • Paper: Yan, Zizhong; Li, Jingrong; Zhang, Yi (2026). “Penalized Likelihood for Dyadic Network Formation Models with Degree Heterogeneity”. arXiv e-prints, arXiv:2605.00771.

  • Software: Yan, Zizhong (2026). “NetworkFm: A Python Package for Dyadic network formation models with degree heterogeneity” (Version 0.8.1) [Computer software]. Available at https://github.com/zizhongyan/networkfm (Accessed 14 February 2026) .

References

  • Graham, Bryan S. (2016). “netrics: a Python 3.7 package for econometric analysis of networks,” (Version 0.0.1) [Computer program]. Available at https://github.com/bryangraham/netrics (Accessed 04 October 2018)
  • Graham, Bryan S. (2017). “An econometric model of link formation with degree heterogeneity,” Econometrica 85 (4): 1033 - 1063
  • Helpman, Elhanan, Marc Melitz, and Yona Rubinstein (2008). “Estimating Trade Flows: Trading Partners and Trading Volumes.” Quarterly Journal of Economics 123: 441–487.
  • Hu, Shiran, Muyang Guo, Xinran Cheng and Xuan Zhou. (2026). “Quadlogit: Quadruple Logit Regression for Network Formation Models,” (Version 0.2.1) [Computer program]. Available at https://github.com/HuNeedHelp/quadlogit (Accessed 30 April 2026)
  • Jochmans, Koen. (2018). “Semiparametric analysis of network formation.” Journal of Business & Economic Statistics 36, no. 4 (2018): 705-713.
  • Yan, Ting, Binyan Jiang, Stephen E. Fienberg and Chenlei Leng. (2019). “Statistical inference in a directed network model with covariates.” Journal of the American Statistical Association 114(526), 857-868.

Code maintainer: Zizhong Yan, Institute for Economic and Social Research (IESR), Jinan University, Guangzhou, China. Email: helloyzz@gmail.com

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

networkfm-0.8.1.tar.gz (29.2 kB view details)

Uploaded Source

Built Distribution

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

networkfm-0.8.1-py3-none-any.whl (27.2 kB view details)

Uploaded Python 3

File details

Details for the file networkfm-0.8.1.tar.gz.

File metadata

  • Download URL: networkfm-0.8.1.tar.gz
  • Upload date:
  • Size: 29.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for networkfm-0.8.1.tar.gz
Algorithm Hash digest
SHA256 bc92da59ef4c68107cfee8d426e6e9aa4c8df9377b40a9b8524703e60d629466
MD5 25f97a4f6e243f937cbcd8712c17ae16
BLAKE2b-256 175aa9cb49626665e7d7fa16d7ffc45259a99b19865cb1dfbd2295295c89e72d

See more details on using hashes here.

Provenance

The following attestation bundles were made for networkfm-0.8.1.tar.gz:

Publisher: python-publish.yml on zizhongyan/networkfm

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

File details

Details for the file networkfm-0.8.1-py3-none-any.whl.

File metadata

  • Download URL: networkfm-0.8.1-py3-none-any.whl
  • Upload date:
  • Size: 27.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for networkfm-0.8.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a64af766ee8621fc8caaab464b37de81d0d4f98dc1cf5eeb22af0cf3cfb4f9e5
MD5 176e735910755e560ee5e1f7c3115e7b
BLAKE2b-256 de3bbe2f88b4ba946ab5407390a4cab42f04632aa4bee50d44c1b5fc2d38c3dc

See more details on using hashes here.

Provenance

The following attestation bundles were made for networkfm-0.8.1-py3-none-any.whl:

Publisher: python-publish.yml on zizhongyan/networkfm

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