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.2.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-5.2-cp311-cp311-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.9+ x86-64

linearmodels-5.2-cp310-cp310-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

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

Uploaded CPython 3.10macOS 10.9+ x86-64

linearmodels-5.2-cp39-cp39-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.9Windows x86-64

linearmodels-5.2-cp39-cp39-win32.whl (2.0 MB view details)

Uploaded CPython 3.9Windows x86

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

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.9macOS 11.0+ ARM64

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

Uploaded CPython 3.9macOS 10.9+ x86-64

File details

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

File metadata

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

File hashes

Hashes for linearmodels-5.2.tar.gz
Algorithm Hash digest
SHA256 1758e8d163c28d235320b2e9ec1578ace2f4532b0a9195af2508da61aeb5b482
MD5 f021eff0f20b78fdbd03ddbaedb4e329
BLAKE2b-256 8dc6cfe058b9ffe5f702907524b6797d16ace3fdcc93dab57983b1a490206a94

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for linearmodels-5.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 fcfa173213ba8d1773c98ae7227a552a07b507406a52f1f8fba797fc6a05e1f1
MD5 494fc282b76db153238c3c7747d28612
BLAKE2b-256 3c189e67d1ee5ce38c340ec871b907025f7ac7f52c9936b643294612ccdbbc4a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-5.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 44268951043cba6fc1c56cc8634da8b6bd143b21d5921749af786817cfe1ec3a
MD5 d34124ecc24049d94189b8ae1af0c575
BLAKE2b-256 f0c5d84ee6dca448ba9afc0bca7f8dec3c16e537df1e7c203f286f54f9209580

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-5.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 640027bc64ca6670c0de8a204415343f125cc180be90a7859b12c3ab775ff860
MD5 131550471f545eb09358033560d43c79
BLAKE2b-256 ae790b5ea3771add9a5eae36d6712901efd7160f712596678176e41dea84c511

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-5.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8f51591d58660e337755de320609d4433457610b8ebf95dd109c2ba80e783226
MD5 c093520dce47a7a4808941ef7c72efad
BLAKE2b-256 65675ba6cc499e91b451c71ed7fd50ece2fce6abca2fbf0e7f1fb7b97e40283a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-5.2-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 6c8a3a5f9b569538de9b8b015f2be7dd34299cd2c7afacfd61e0e8e2786c1b74
MD5 837d176abba72c5e04f018ed10c328d4
BLAKE2b-256 0d85581ff935db4b7d2502a480ecb25575d103fe4482641342e3b95e861fef8b

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for linearmodels-5.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d17ebd694db8a12067c92024bb0fbd6c371554e21fd030df11d03311c707ee22
MD5 2e4544008f5d90fbf50b473ae41517ad
BLAKE2b-256 5c508fef9ef06ffd6755279c21be60b04af6e81d27011104017fc9d3f42855bd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-5.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 772ec72db01d8e57cce789b31d653ae57e7c4946ed74e5d1e6adb9f966d0c476
MD5 e46a3785fb6f74117f78ac754aa94015
BLAKE2b-256 835b48c4101c09ef41530774aafd12b1620286496e0155ac8d2dfb3a50994a72

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-5.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b47aa34d945ce20396289ab3e34abf812ace7c2a15a03893a3b93b49cae8ea77
MD5 22c5f7087ea6daabf4461ea0c3df16e2
BLAKE2b-256 d5229054fbcdbfe83d05bd932fa1475bed2f4ae9ef552ff4e02298cc6a3e2f02

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-5.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7e1fd116f4e1b1f3b99d8ab64ba60040411af3207f687d9535bf80f828006182
MD5 aba2b97aec6eefb659a3f66d25ee836e
BLAKE2b-256 efe3e180a3625478025a1236be47d5f72e5e3c28db543ff20809cc80250d296c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-5.2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 aa58ad50e7c0b8c25f07dbc6d8467388e46b728c76cbb65814a19e0d9b2452d9
MD5 a8da6035d6345b9c86474ec5a145a6f1
BLAKE2b-256 df4df2885d73556a93ec4d756e07c6d938fea65595e87f8ce1c6a7581fb967b9

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for linearmodels-5.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 c9ad17ad7b2db7eede5485ef98a1d4245416b8c24aecb2212fae55a4a586eb11
MD5 43e919f6fb44b62ff9b1e35951b93451
BLAKE2b-256 3672def17adab3ad41973aa3e51acac43cf4d66b48bc431f93dae376047b7eb3

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for linearmodels-5.2-cp39-cp39-win32.whl
Algorithm Hash digest
SHA256 e80265742c3b1c9140aeb604dd690029f179d6c5751f60a81a3e3c376e5c6f86
MD5 a255a38d82e1e25fce2f807d6e3ffb85
BLAKE2b-256 5736ec112b1242fa81ee301960f998cd1324dea91b0375ac5e7a43699a386246

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-5.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1e6452a302e195e388ff274886a3a7b3905858246fa23e5cba4ec0344bbcf704
MD5 30ce9f76a1a446a90f49436deb39d114
BLAKE2b-256 a2b7628b1eb1d393c4aa2dfbfce77b4481b5b70f89fedee20d779952a9ed1014

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-5.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 08b50328fff13464f3fedb3a58cf0d66a5e57279e42cd18e2f51e5a132db3a79
MD5 99c1451f0bcf127bd01bf541e4831dde
BLAKE2b-256 b74ccee9d2ca61e56f920d55badd489cdedc6d3acd3fb5bc81933563eb8b7e55

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-5.2-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cf31d1221c9565f5a84ad657819b50a751213d8dbcb9d66a4f51c6c360ee6e7c
MD5 6d2a6a7fa3476e07968269703ded1cfc
BLAKE2b-256 590f011b9789e2b6a0382473d905cf05a7f5b281b3e4d2b2eeb59da28af17e7b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-5.2-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 e87159305c4382ccf92fb97ff6bd738ddfc8cc577d114c92af0bbe8808979980
MD5 896a46279df868835fc616faab361019
BLAKE2b-256 4aac8d4787238f9ca918d280fb631afdb72cf989a19f7732f1c3315fab0f7340

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