https://github.com/bashtage/linearmodels

Additional linear models including instrumental variable and panel data models that are missing from statsmodels.

https://github.com/bashtage/linearmodels

Science Score: 46.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: zenodo.org
  • Committers with academic emails
    1 of 16 committers (6.3%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (9.3%) to scientific vocabulary

Keywords

asset-pricing between-estimator clustered-standard-errors fama-macbeth first-difference fixed-effects gmm instrumental-variable iv linear-models ols panel panel-data panel-models panel-regression pooled-ols random-effects regression seemingly-unrelated-regression statistical-model

Keywords from Contributors

econometrics regression-models profiler closember count-model generalized-linear-models hypothesis-testing prediction robust-estimation timeseries-analysis
Last synced: 5 months ago · JSON representation

Repository

Additional linear models including instrumental variable and panel data models that are missing from statsmodels.

Basic Info
Statistics
  • Stars: 1,006
  • Watchers: 25
  • Forks: 185
  • Open Issues: 50
  • Releases: 45
Topics
asset-pricing between-estimator clustered-standard-errors fama-macbeth first-difference fixed-effects gmm instrumental-variable iv linear-models ols panel panel-data panel-models panel-regression pooled-ols random-effects regression seemingly-unrelated-regression statistical-model
Created about 9 years ago · Last pushed 6 months ago
Metadata Files
Readme License

README.md

Linear Models

| Metric | | | :------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Latest Release | PyPI version | | Continuous Integration | Build Status | | Coverage | codecov | | Code Quality | Codacy Badge | | | codebeat badge | | Citation | DOI |

Linear (regression) models for Python. Extends statsmodels with Panel regression, instrumental variable estimators, system estimators and models for estimating asset prices:

  • Panel models:

    • Fixed effects (maximum two-way)
    • First difference regression
    • Between estimator for panel data
    • Pooled regression for panel data
    • Fama-MacBeth estimation of panel models
  • High-dimensional Regresssion:

    • Absorbing Least Squares
  • Instrumental Variable estimators

    • Two-stage Least Squares
    • Limited Information Maximum Likelihood
    • k-class Estimators
    • Generalized Method of Moments, also with continuously updating
  • Factor Asset Pricing Models:

    • 2- and 3-step estimation
    • Time-series estimation
    • GMM estimation
  • System Regression:

    • Seemingly Unrelated Regression (SUR/SURE)
    • Three-Stage Least Squares (3SLS)
    • Generalized Method of Moments (GMM) System Estimation

Designed to work equally well with NumPy, Pandas or xarray data.

Panel models

Like statsmodels to include, supports formulas for specifying models. For example, the classic Grunfeld regression can be specified

```python import numpy as np from statsmodels.datasets import grunfeld data = grunfeld.load_pandas().data data.year = data.year.astype(np.int64)

MultiIndex, entity - time

data = data.setindex(['firm','year']) from linearmodels import PanelOLS mod = PanelOLS(data.invest, data[['value','capital']], entityeffects=True) res = mod.fit(covtype='clustered', clusterentity=True) ```

Models can also be specified using the formula interface.

python from linearmodels import PanelOLS mod = PanelOLS.from_formula('invest ~ value + capital + EntityEffects', data) res = mod.fit(cov_type='clustered', cluster_entity=True)

The formula interface for PanelOLS supports the special values EntityEffects and TimeEffects which add entity (fixed) and time effects, respectively.

Formula support comes from the formulaic package which is a replacement for patsy.

Instrumental Variable Models

IV regression models can be similarly specified.

python import numpy as np from linearmodels.iv import IV2SLS from linearmodels.datasets import mroz data = mroz.load() mod = IV2SLS.from_formula('np.log(wage) ~ 1 + exper + exper ** 2 + [educ ~ motheduc + fatheduc]', data)

The expressions in the [ ] indicate endogenous regressors (before ~) and the instruments.

Installing

The latest release can be installed using pip

bash pip install linearmodels

The main branch can be installed by cloning the repo and running setup

bash git clone https://github.com/bashtage/linearmodels cd linearmodels pip install .

Documentation

Stable Documentation is built on every tagged version using doctr. Development Documentation is automatically built on every successful build of main.

Plan and status

Should eventually add some useful linear model estimators such as panel regression. Currently only the single variable IV estimators are polished.

  • Linear Instrumental variable estimation - complete
  • Linear Panel model estimation - complete
  • Fama-MacBeth regression - complete
  • Linear Factor Asset Pricing - complete
  • System regression - complete
  • Linear IV Panel model estimation - not started
  • Dynamic Panel model estimation - not started

Requirements

Running

  • Python 3.10+
  • NumPy (1.22+)
  • SciPy (1.8+)
  • pandas (1.4+)
  • statsmodels (0.13.1+)
  • formulaic (1.0.0+)
  • xarray (0.16+, optional)
  • Cython (3.0.10+, optional)

Testing

  • py.test

Documentation

  • sphinx
  • sphinx-immaterial
  • nbsphinx
  • nbconvert
  • nbformat
  • ipython
  • jupyter

Owner

  • Name: Kevin Sheppard
  • Login: bashtage
  • Kind: user
  • Location: London, UK

GitHub Events

Total
  • Issues event: 7
  • Watch event: 63
  • Delete event: 38
  • Issue comment event: 40
  • Push event: 35
  • Pull request review comment event: 1
  • Pull request review event: 1
  • Pull request event: 33
  • Fork event: 6
  • Create event: 21
Last Year
  • Issues event: 7
  • Watch event: 63
  • Delete event: 38
  • Issue comment event: 40
  • Push event: 35
  • Pull request review comment event: 1
  • Pull request review event: 1
  • Pull request event: 33
  • Fork event: 6
  • Create event: 21

Committers

Last synced: 9 months ago

All Time
  • Total Commits: 734
  • Total Committers: 16
  • Avg Commits per committer: 45.875
  • Development Distribution Score (DDS): 0.045
Past Year
  • Commits: 19
  • Committers: 1
  • Avg Commits per committer: 19.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Kevin Sheppard k****d@g****m 701
Kevin Sheppard k****d@g****m 17
Joon Ro j****o@o****m 2
snyk-bot s****t@s****o 2
Brian Lewis b****s@g****m 1
Christian Clauss c****s@m****m 1
Jan Fan g****n@g****m 1
Jeff j****4@g****m 1
Jerry Qinghui Yu q****u@m****u 1
Jiageng j****6@g****m 1
Kevin Wilson k****n@g****m 1
LGTM Migrator l****r 1
Thrasibule t****e 1
William Nelson w****n@g****m 1
Xavier RENE-CORAIL x****l@g****m 1
vikjam v****m@g****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 47
  • Total pull requests: 208
  • Average time to close issues: 30 days
  • Average time to close pull requests: about 1 month
  • Total issue authors: 44
  • Total pull request authors: 11
  • Average comments per issue: 3.49
  • Average comments per pull request: 0.65
  • Merged pull requests: 94
  • Bot issues: 0
  • Bot pull requests: 1
Past Year
  • Issues: 4
  • Pull requests: 34
  • Average time to close issues: about 6 hours
  • Average time to close pull requests: 5 days
  • Issue authors: 4
  • Pull request authors: 2
  • Average comments per issue: 2.0
  • Average comments per pull request: 0.5
  • Merged pull requests: 13
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • spring-haru (3)
  • yurivict (2)
  • Paq70 (1)
  • blakemas (1)
  • gregor-schueler (1)
  • nick-zhy (1)
  • hachemathieu (1)
  • jonnatakusuma (1)
  • baharcos (1)
  • MaxGhenis (1)
  • ignacio-rh (1)
  • cearlefraym (1)
  • vgreg (1)
  • roy1312 (1)
  • yuz0101 (1)
Pull Request Authors
  • bashtage (194)
  • snyk-bot (12)
  • joonro (2)
  • bernardodionisi (1)
  • lgtm-com[bot] (1)
  • cclauss (1)
  • eirki (1)
  • jiagengliu (1)
  • WilliamRoyNelson (1)
  • jaimeoliver1 (1)
  • maharris77 (1)
Top Labels
Issue Labels
enhancement (2)
Pull Request Labels

Packages

  • Total packages: 2
  • Total downloads:
    • pypi 223,974 last-month
  • Total docker downloads: 1,574
  • Total dependent packages: 22
    (may contain duplicates)
  • Total dependent repositories: 155
    (may contain duplicates)
  • Total versions: 51
  • Total maintainers: 1
pypi.org: linearmodels

Linear Panel, Instrumental Variable, Asset Pricing, and System Regression models for Python

  • Versions: 44
  • Dependent Packages: 22
  • Dependent Repositories: 152
  • Downloads: 223,974 Last month
  • Docker Downloads: 1,574
Rankings
Dependent packages count: 0.6%
Dependent repos count: 1.2%
Downloads: 1.3%
Average: 1.9%
Stargazers count: 2.2%
Docker downloads count: 2.4%
Forks count: 3.9%
Maintainers (1)
Last synced: 6 months ago
conda-forge.org: linearmodels

Linear (regression) models for Python. Extends statsmodels with Panel regression, instrumental variable estimators, system estimators and models for estimating asset pricing models.

  • Versions: 7
  • Dependent Packages: 0
  • Dependent Repositories: 3
Rankings
Forks count: 14.2%
Stargazers count: 14.9%
Dependent repos count: 18.1%
Average: 24.7%
Dependent packages count: 51.6%
Last synced: 6 months ago

Dependencies

doc/requirements.txt pypi
  • ipython *
  • jupyter *
  • matplotlib *
  • mistune <2
  • mypy_extensions >=0.4
  • nbformat *
  • nbsphinx *
  • notebook *
  • seaborn *
  • sphinx *
  • sphinx_autodoc_typehints *
  • sphinx_material *
  • sphinxcontrib.spelling *
  • xarray >=0.13
requirements-dev.txt pypi
  • black ==22.3.0
  • ipython *
  • isort >=5.10
  • jupyter *
  • matplotlib *
  • mypy >=0.930
  • nbconvert *
  • nbformat *
  • nbsphinx *
  • numpydoc *
  • pygments >=2.7.4
  • pytest >=6.0
  • pytest-cov *
  • pytest-xdist *
  • seaborn *
  • sphinx *
  • sphinx-material *
  • sphinx_autodoc_typehints *
  • sphinxcontrib-spelling *
  • wheel *
  • xarray >=0.13
requirements-test.txt pypi
  • black ==22.3.0
  • coverage *
  • flake8 *
  • isort *
  • matplotlib *
  • pytest >=6.0
  • pytest-cov *
  • pytest-xdist *
  • seaborn *
  • wheel *
  • xarray >=0.13
requirements.txt pypi
  • Cython >=0.29.21
  • formulaic *
  • mypy_extensions >=0.4
  • numpy >=1.16
  • pandas >=0.24
  • property_cached >=1.6.3
  • pyhdfe >=0.1
  • scipy >=1.2
  • setuptools_scm >=6.4.2,<7.0.0
  • statsmodels >=0.11
.github/workflows/codeql.yml actions
  • actions/checkout v3 composite
  • github/codeql-action/analyze v2 composite
  • github/codeql-action/autobuild v2 composite
  • github/codeql-action/init v2 composite
.github/workflows/cron-test.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
.github/workflows/generate-documentation.yml actions
  • actions/checkout v2 composite
  • actions/setup-python v2 composite
  • r-lib/actions/setup-pandoc v1 composite
pyproject.toml pypi
setup.py pypi