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
Code Quality: Python
Total Alerts
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

With the exception of Python 3 (3.8+ tested), which is a hard requirement, the others are the version that are being used in the test environment. It is possible that older versions work.

  • Python 3.8+
  • NumPy (1.18+)
  • SciPy (1.3+)
  • pandas (1.0+)
  • statsmodels (0.12+)
  • xarray (0.16+, optional)
  • Cython (0.29.24+, optional)

Testing

  • py.test

Documentation

  • sphinx
  • sphinx-material
  • 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-4.28.tar.gz (1.8 MB view details)

Uploaded Source

Built Distributions

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

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

Uploaded CPython 3.11Windows x86-64

linearmodels-4.28-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-4.28-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.8 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

linearmodels-4.28-cp311-cp311-macosx_11_0_arm64.whl (1.8 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

linearmodels-4.28-cp311-cp311-macosx_10_9_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

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

Uploaded CPython 3.10Windows x86-64

linearmodels-4.28-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-4.28-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.8 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

linearmodels-4.28-cp310-cp310-macosx_11_0_arm64.whl (1.8 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

linearmodels-4.28-cp310-cp310-macosx_10_9_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

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

Uploaded CPython 3.9Windows x86-64

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

Uploaded CPython 3.9Windows x86

linearmodels-4.28-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-4.28-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.8 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

linearmodels-4.28-cp39-cp39-macosx_11_0_arm64.whl (1.8 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

linearmodels-4.28-cp39-cp39-macosx_10_9_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

linearmodels-4.28-cp38-cp38-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.8Windows x86-64

linearmodels-4.28-cp38-cp38-win32.whl (1.9 MB view details)

Uploaded CPython 3.8Windows x86

linearmodels-4.28-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

linearmodels-4.28-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.8 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ ARM64

linearmodels-4.28-cp38-cp38-macosx_11_0_arm64.whl (1.8 MB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

linearmodels-4.28-cp38-cp38-macosx_10_9_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: linearmodels-4.28.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-4.28.tar.gz
Algorithm Hash digest
SHA256 de3a2b99e0efbbf4419f04f1221dfabe5dbc66e8f82826aa63880199e5e8659e
MD5 5d2a762297b8036bcdb9a437d384a084
BLAKE2b-256 75a4f3a9752c93032ec5ae7b33dc6c6ffc0245d488b79faa882f96bad590b150

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-4.28-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 9c77615844d97f484fafa475d4fb708b524ac77251b3cb2042d1348b33dc07bf
MD5 a591d2c75cafefa177eb2c46f515d997
BLAKE2b-256 b81c1cf0d10ad5531242c93d7eef5de0042d6bf9c6759651fe88003a8a65b407

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-4.28-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7470b9d70518698ee919cdc98b9c05424af48200714e027106ea2bb22d481b5c
MD5 2156cb41966839e32b927d35de47eb08
BLAKE2b-256 978b6d7f11509cf634771368bbb10abb757e98dc675233fbf303868b31791fb7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-4.28-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4ede97a4d45df2df43599146e6c6b111fddb455b02888c6b79143c8bc5045f9a
MD5 6e686cb54a02d31a418522454bde56a5
BLAKE2b-256 34dd6d6738cb930d15c39834c510269130580901356cad43e6aad65dc500c159

See more details on using hashes here.

File details

Details for the file linearmodels-4.28-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for linearmodels-4.28-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9b83fd3ccae9cf8f195de1c6a3415fc998dd346ba8dccf44290721b1ad93fde1
MD5 30c35ca0121c038ba5ba6741d78859b2
BLAKE2b-256 fc0652408562776e2d116e0ee4c15eaa5e450b4bb5ead185f91084b4b1ef0231

See more details on using hashes here.

File details

Details for the file linearmodels-4.28-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for linearmodels-4.28-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 7780e95645181603eb6a35f543a24c00a3942e907b435b9eb68af2d50e07a243
MD5 a27b2bdd457d7baa50339c90abb3c252
BLAKE2b-256 eb1050c552c7a18994876d9dc4ebadc089734682d32e8e1be081cc0fa4e5c974

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-4.28-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 234e6ba94964ae1d2e964bc66d69135b9a4b636788660bca02b136e133142dc2
MD5 f054b532d56f000c17fa680208f80b76
BLAKE2b-256 806a562002a90db730e35b2c79fbc320cff1ae25ca1c81fef25456ddf50b651f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-4.28-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3a7e8c165e7cf097dba73bf11cb7135b4a3f11915542912222356fe743e831c0
MD5 3566a56c8332c1c6a41d8e722ab0f93f
BLAKE2b-256 6a115c506b9690c4d219cff2d7941910f3cb38abcc5a43da2761367f8c75f538

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-4.28-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 bb85d442a5c848f41ae9b349c14ea775db64d718b8becadc89f625ae8ec8a0a5
MD5 667e319dbbe1767fa999bceb5e8795d0
BLAKE2b-256 e4e9223616e7836f8f2acf6847fa7e595adae072357438e5131c9ee6614fe088

See more details on using hashes here.

File details

Details for the file linearmodels-4.28-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for linearmodels-4.28-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1ecd30eac971b41906f9d43f08c605f08661c23438aea3541ff863149bfbdaf5
MD5 190d8580da5ac1758832976ac0ba8c35
BLAKE2b-256 47aeafb3c5f814ab01430467c1312c75ee417a2ba7e356ac7eb22eed7ba4f425

See more details on using hashes here.

File details

Details for the file linearmodels-4.28-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for linearmodels-4.28-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 d427b84e50fc0b45850162e640b616f22d48be1bc41c62cfc7f3e84259a56ff3
MD5 8ec6a4b3574f57456fb1a5e62a23a0d5
BLAKE2b-256 9ea6eb3da6aed6a8ab4a1dbb37619e4771572f10b4cb979d30cdf8f293d24e03

See more details on using hashes here.

File details

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

File metadata

  • Download URL: linearmodels-4.28-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.2

File hashes

Hashes for linearmodels-4.28-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 efab586122597af6a2b16247812b0c292084727a707afa2be6b84376a00b7fdf
MD5 7b9686a2353abea0f91095a6f9afacf9
BLAKE2b-256 6f5b9e8e590cba84e810fd5dd9e2d7c6534d9f00261cd9f8a7f2b499836d2203

See more details on using hashes here.

File details

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

File metadata

  • Download URL: linearmodels-4.28-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.2

File hashes

Hashes for linearmodels-4.28-cp39-cp39-win32.whl
Algorithm Hash digest
SHA256 7674829f4bbcd599d4a66155999d987da10d6413f11893998466833e3f3572c9
MD5 83fd09c3794ee1003d66d10fa3cc14ca
BLAKE2b-256 d590028c7f65a868fb438b990646e1925c0e17b8c35528a600032aff7b938f96

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-4.28-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b7d124013e5a3c9a01bdc0cf2a1bc0e471cbe0f8bac21cef2230a48c8c2dc5f0
MD5 4187a690b27338ac9650983da0ad204f
BLAKE2b-256 10f26b6d8fc9679e6b3dbab1faeb6664b1ac6de3f6bdb7e2977d340ac47529c2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-4.28-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e63604ce0918cd85012bbc36be8f014676ec4cc00a1293e0724372f81f623b73
MD5 2c7ad7ac47385bf08a233d5df9b1fa27
BLAKE2b-256 2702595a24813ca187dbf5e35be67217d876b3e1b348d5e4f96b1f2e5c360862

See more details on using hashes here.

File details

Details for the file linearmodels-4.28-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for linearmodels-4.28-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f67b20080c6093a3809bbe0a627fcbc102a4d575225b1505ea6c8a015c941365
MD5 00586d7ae65fb27aa42b7fe9db51f5a5
BLAKE2b-256 57c63f5509c0c1a7f9453b3dc42f7a786fd33c8f5a79aa81cb4b31844e208f0b

See more details on using hashes here.

File details

Details for the file linearmodels-4.28-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for linearmodels-4.28-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 e4d21adbc0a9867a909d1c111202de21c7da2c9d9f672dda6ed2ca81a924bfb6
MD5 6ee6e680c1d4f912f11da885cd91b43d
BLAKE2b-256 f236644d62501dbed94c0de317d37bb786d29d7c39353f678b0e8f7bf6306399

See more details on using hashes here.

File details

Details for the file linearmodels-4.28-cp38-cp38-win_amd64.whl.

File metadata

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

File hashes

Hashes for linearmodels-4.28-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 50a80040ee246fe0ec8f19053a15a645bfd4cce693ffab295f6dbe0b0a93f72c
MD5 7e998816b1c3eae0b536ff96ba086b55
BLAKE2b-256 c7c4dda24abfdf3078924b445da985d11509d8ef88d86c937c9ba18d33672d19

See more details on using hashes here.

File details

Details for the file linearmodels-4.28-cp38-cp38-win32.whl.

File metadata

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

File hashes

Hashes for linearmodels-4.28-cp38-cp38-win32.whl
Algorithm Hash digest
SHA256 60e587f9de94a9188c164e01c87c5261f381c43a66415bd8bc4f22dbaa7e565b
MD5 c1718732eac1f466ad957cee69665d31
BLAKE2b-256 df6e4e6aebcf853837e29e5d3871036543c84f9a3c69345fe7ad402906d7d289

See more details on using hashes here.

File details

Details for the file linearmodels-4.28-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for linearmodels-4.28-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ff4b7948a5c3d8563f7d6e8898bb463c2601b60a671b0a3d9aa24ed99ac247c8
MD5 a52fc93566d68705772ee9b3e2df7188
BLAKE2b-256 99391472f067aec102e95552e344ef84357e20c67dab76cda9eac14015804cfd

See more details on using hashes here.

File details

Details for the file linearmodels-4.28-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for linearmodels-4.28-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6a0b89654a20e4b0f4b591daae66f32303ed95eff4a1954f696211657f3cc5d6
MD5 6623b7bf5fc28421dd723ffd0123f422
BLAKE2b-256 3fd5951e721fd4405a2d6710c9dbb4323071f713a14b268b1cb457b9fff4bacd

See more details on using hashes here.

File details

Details for the file linearmodels-4.28-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for linearmodels-4.28-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8b0d4e97d108b5ad84c6c703d3e87fb3800164bcf3c6c04a5135838713eacf41
MD5 5ed5dc1bc0778ca694d4d703dd51ceee
BLAKE2b-256 26433a8d883e73dafb966ad03275678e6a9be2e6e6e38afe4941cd230ba6fec0

See more details on using hashes here.

File details

Details for the file linearmodels-4.28-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for linearmodels-4.28-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 0489041771fc09d9a07d69aca3b4e977d59375fe28fa7696036b1498f559a57c
MD5 4a3f278b6a48cd9d0fac40a037d9e2dd
BLAKE2b-256 d108558a5e5f40537165a0d3ed79a3f576d8eef61d89ec5057d19cee4d2ab6d5

See more details on using hashes here.

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