Skip to main content

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

Project description

Linear Models

Metric
Latest Release PyPI version
Continuous Integration Build Status
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

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.set_index(['firm','year'])
from linearmodels import PanelOLS
mod = PanelOLS(data.invest, data[['value','capital']], entity_effects=True)
res = mod.fit(cov_type='clustered', cluster_entity=True)

Models can also be specified using the formula interface.

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.

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

pip install linearmodels

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

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.9+
  • NumPy (1.19+)
  • SciPy (1.5+)
  • pandas (1.1+)
  • statsmodels (0.12+)
  • xarray (0.16+, optional)
  • Cython (0.29.34+, optional)

Testing

  • py.test

Documentation

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

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

linearmodels-5.0.tar.gz (1.8 MB view details)

Uploaded Source

Built Distributions

linearmodels-5.0-cp311-cp311-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.11Windows x86-64

linearmodels-5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

linearmodels-5.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.8 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

linearmodels-5.0-cp310-cp310-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.10Windows x86-64

linearmodels-5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

linearmodels-5.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.8 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

linearmodels-5.0-cp39-cp39-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.9Windows x86-64

linearmodels-5.0-cp39-cp39-win32.whl (1.9 MB view details)

Uploaded CPython 3.9Windows x86

linearmodels-5.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

linearmodels-5.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.8 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

File details

Details for the file linearmodels-5.0.tar.gz.

File metadata

  • Download URL: linearmodels-5.0.tar.gz
  • Upload date:
  • Size: 1.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.12

File hashes

Hashes for linearmodels-5.0.tar.gz
Algorithm Hash digest
SHA256 2642be561fedbd9351479f9c1587e02bb3ff4972954044e5353a9bcfa8d366a9
MD5 c503afc870851b4f3e4146afd5b1e328
BLAKE2b-256 1d65b7d0f624af7c74c6d9d28cca9f1ff8e62a8585a867c9f51f41520e2bfb75

See more details on using hashes here.

File details

Details for the file linearmodels-5.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: linearmodels-5.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for linearmodels-5.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f76e52c567782ab8eabcece3efe4c27a7f7687bcd3db102a9c3e6866e39111d9
MD5 a5617d67f2d88b86c18d2c08c4c3bfa8
BLAKE2b-256 3af397776a3a3d4e1686a5726aa8494f640b06e977c7fb1b89963df1b67b3aa2

See more details on using hashes here.

File details

Details for the file linearmodels-5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for linearmodels-5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 add65bcd6f118ab84ec08219207ebf54d8a3e6d3a18785f1b013a65744bccb49
MD5 9267fa342e4bd2339bae712758ff57e0
BLAKE2b-256 c05eb7e230b25f548b4f4214bbd15ba011ed58234c29be7bae283dfd20215554

See more details on using hashes here.

File details

Details for the file linearmodels-5.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for linearmodels-5.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6740ff846f4b418c4efd2346477a5afe79ea8f822bfbb2f66a33ac5518969d5a
MD5 89f9244996ae958dce09aa06e2b6f92d
BLAKE2b-256 2f9737538a8c755db0838daf1ae4ae82af2185c4ceb43d8261bca857611daff0

See more details on using hashes here.

File details

Details for the file linearmodels-5.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: linearmodels-5.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for linearmodels-5.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 f16c9375a46eaf344cfbae2ce4532a67196d2b8f60edb55fa93b748101978b33
MD5 46aacc67c2821efdfa0c4df4d1553fe2
BLAKE2b-256 897b513353970d09429ba1dad7081b596eb28e3128a3ed992dba79e8f87b6cd8

See more details on using hashes here.

File details

Details for the file linearmodels-5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for linearmodels-5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 36c0e55407180491676eeac1242e28b6463af931f3429c27d901d81d277770a6
MD5 d95a72c37019817dfa4dd97957e7a46a
BLAKE2b-256 c5214c14d67482098228f4ddea869113cc208a5f5e3e3fe0706923f69d2d884e

See more details on using hashes here.

File details

Details for the file linearmodels-5.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for linearmodels-5.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f0888fea1cbfc6094a360d7fe17e9fe31862148c9751bb6a0e6e6180baf10a6c
MD5 69319b8c47d8f2427f1f41bbbb327bbe
BLAKE2b-256 f405259ea9442635ba5a4bce6a19b868074ece71b13472f79af40d1c8f99d5b9

See more details on using hashes here.

File details

Details for the file linearmodels-5.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: linearmodels-5.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for linearmodels-5.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 13122d62601950f111df22ced5a5030e1a98adb0b06fa3266b6d67d3cac4c016
MD5 ea27d23a44216a0786145e4e4c60165a
BLAKE2b-256 84f4854e923b08e6c9d9afa676143c273676cd929b9d5db9996421f308696826

See more details on using hashes here.

File details

Details for the file linearmodels-5.0-cp39-cp39-win32.whl.

File metadata

  • Download URL: linearmodels-5.0-cp39-cp39-win32.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: CPython 3.9, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for linearmodels-5.0-cp39-cp39-win32.whl
Algorithm Hash digest
SHA256 ace246e14b9a1bcd036e001307aae03648f2f573aa5c4e8fee85dc47bde5b114
MD5 ac240e69289d5d731d76747c1399f853
BLAKE2b-256 6eaef269e1bb254aaf692930ce2655e069d0f709de9009309dbf2d49443f6991

See more details on using hashes here.

File details

Details for the file linearmodels-5.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for linearmodels-5.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1446e8db914f538dc1f6e3b77aa7c4cc4553e6405218b6d694de5ce1f35a5979
MD5 155482f13603f55e963b3a9742e6963d
BLAKE2b-256 4a4545dd9bcc7af295abb5ff7a8cc685562ba31db0b09a5954e4263f39229a07

See more details on using hashes here.

File details

Details for the file linearmodels-5.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for linearmodels-5.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 9a39e504b98ae82813649e7d7369e8a21525b66773a01e7fe493114080acf1b6
MD5 a5980ca19f4f2fa0306e0d7d232b1812
BLAKE2b-256 0062f580958e8ce711e26b3757f76fb56651c981349b1a3b2f4aeafd29822bff

See more details on using hashes here.

Supported by

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