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

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-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-4.31.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.31-cp311-cp311-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.9+ x86-64

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

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

Uploaded CPython 3.10macOS 10.9+ x86-64

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

Uploaded CPython 3.9Windows x86-64

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

Uploaded CPython 3.9Windows x86

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

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.9macOS 11.0+ ARM64

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

Uploaded CPython 3.9macOS 10.9+ x86-64

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

Uploaded CPython 3.8Windows x86-64

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

Uploaded CPython 3.8Windows x86

linearmodels-4.31-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.31-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.8 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.8macOS 11.0+ ARM64

linearmodels-4.31-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.31.tar.gz.

File metadata

  • Download URL: linearmodels-4.31.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.31.tar.gz
Algorithm Hash digest
SHA256 78a00ebd0360c2886357e8197faca174dc4521256a01e9f24114054bca676be9
MD5 8d9b9da4d47ce8316dc80af1ad68bdda
BLAKE2b-256 90a6f596cba76dcee2a704e9789d987331044cfb0aa3d1e674f373c10047c556

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-4.31-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 4cc382c922de7278e10e08f69aec18ecaf212fc86b4718eb36faf811509037b8
MD5 002791869a9356eab4365a8a142b76d4
BLAKE2b-256 3d69a3af32330a39123bee2212284f8cf058b0262b8a5dee3fbeb3aaf706159e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-4.31-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dc2dca305579129bb801aa3b1fa7471304c6b94400b80bf97345be5f38fa6566
MD5 35a5cac2d9e658bb6c3b84a6fc115660
BLAKE2b-256 245ae7a58f37ade7b92a4313ee635c1dab1eb93ede22a5403cbf7b769e82027b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-4.31-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 968720a990759afd7c37f8eb54c368f94e5b40b1491339b8a649f06677f67a61
MD5 b028f127284f89eb6bdfdb3f888e8319
BLAKE2b-256 c927920da700ecea5fa088b0ef6888616d122a8e26a4cf4e6da2da19c87e1dd2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-4.31-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8b4452934fbbf969596028f4e3cfb68fc5b31feb39f2e8dcf90c60480b7dd80b
MD5 52fb1b9423c6dd08ab0b6e5e4a3ee5d9
BLAKE2b-256 63efe89526680ce4aacd628d5cf0fa20e206c7a71a04779e98b48f01abdd233f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-4.31-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 8b48da80ec81176745f125f1a10cb9cc549ea9dd7275da7406ad49092d925bd3
MD5 0c357215b57e82557b443e63fe4d50f1
BLAKE2b-256 009bd07b6f205c94821f0e21807ba554949c1be9f32b054630a5108eaeca23ac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-4.31-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 6b6f23d22b373f2be628bb5e3751c08ebb99cb7be6eb7698420596efd95bdd91
MD5 f3a5f3567bb66593ceae467e71294849
BLAKE2b-256 a16f5bcd601698b6ce2ccdd5457f47c8adf6edd05fed301b203ba182d70353fa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-4.31-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3df2f7398d94ce25683c0a71c5b8c85fe588e8eae88303c4404b1391f7387195
MD5 5cddd1ec4a46efac3a15140866cfca9f
BLAKE2b-256 6e3bc89fb8ececd2ed84ffaa55e03f4c258a7aba64d7aad4221afe4e10ef0cae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-4.31-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 cac9aa59859834fea6d0db3ad3fdcf828aa40d6226ca0043e39bec108a171ce5
MD5 c0a08ab46963a630cd8d625c093c86fe
BLAKE2b-256 63df470a44b8c5e4173142a20d2c913d4bca5cd4705839be860b2e61de02e26a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-4.31-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 248b6c325997c9e322d7c270bc89d7f3c8c6bc394053bb3ccd0d061e57a9b398
MD5 555f04938ce519c7d49a56cd80befcdf
BLAKE2b-256 eff76f6bef451ef3de8abece1351a99b7feee5c345341922db182f71f5fd5757

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-4.31-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 9b8099d476526bba1f8709ffbfaf868aac1db70e7c1607b6f1aa36913ab930d9
MD5 4635276654efd66f50e8b6b3cbd6be7c
BLAKE2b-256 fe2e311ebea0018022a91ca25cbf9d87bbf820a7aaf969f04781fd449bd19922

See more details on using hashes here.

File details

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

File metadata

  • Download URL: linearmodels-4.31-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-4.31-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 24cda8759583a7c3d179efee9e1e502092c8794774c6334f87b2b131869fd9dd
MD5 e91eec51c9b5c4ce4c74106b217caaf3
BLAKE2b-256 310bcf7f95de644aa8f40ae38f501d588d734f20ae496d11f8e2cfe6b94e2c27

See more details on using hashes here.

File details

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

File metadata

  • Download URL: linearmodels-4.31-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-4.31-cp39-cp39-win32.whl
Algorithm Hash digest
SHA256 4222bd5748fa662173fc44214b7dcf04f68775550a7014045c6bb07741ae2153
MD5 2b066786e6afddc59ac8852bcc0107ef
BLAKE2b-256 c39c7dcf5414039b3270f2156e69d2b56d8d353eb411042adc8167417eab7325

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-4.31-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9f0a033e66cdf336e682f8a48de44512362ae96fad6e0b3def7f83c01f1d346e
MD5 8346cbd45aef9841e73bb7dd8b8fce93
BLAKE2b-256 c8e33fac45d87485d3387119da1c42c68e7705043d11081de631b1e22d7ee971

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-4.31-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f7c9b245f33c573cdf983dc7eecc5d593ea51b9f17799fbd89902856797359e8
MD5 c26b91b6736138900a3c97fd42dd0039
BLAKE2b-256 0a4a76fe7d08bfb100d80fb7fa53175e8296d191710a14f964315d5a3aa3a13c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-4.31-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 15737df58e9a13f847f6f3e2e296255082bcf2cd8183b64e629d7252a50fbb91
MD5 eb011160f9d902f9a5387222c1e72d33
BLAKE2b-256 e8de40bb4e02e9a209b70ced4450b8a9907f76d63b5a5b0271de007c65318a0f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-4.31-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 de2579b18a277d41b215292c7514a8c325b511c1f5a35aefbfe89fdd666a8c7f
MD5 4b7620b35125a5586a8aa50c1f07c1f7
BLAKE2b-256 c624b79b80fc9e742a824244b75f5ac8817f15d3f75020292ce353c86d3cfa72

See more details on using hashes here.

File details

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

File metadata

  • Download URL: linearmodels-4.31-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.31-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 663084a878b9e801f0aae261dfb999af37d385f5c7d8b67930cefab490d7b166
MD5 cc9b177b0e5636ab10ab9099ebc5302f
BLAKE2b-256 2af85f5ec5c11720ddc92f8656369580f6d0933fafe06293c9c74fbeb1be1a4c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: linearmodels-4.31-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.31-cp38-cp38-win32.whl
Algorithm Hash digest
SHA256 657647d22e4d05dbf444bd154fb40c9b01b516c3af7e9fe0b8624c2fcb5f9e6a
MD5 ddc13d09edf0d1b69f279b08280dc239
BLAKE2b-256 7c8cf7237eb35a3e83e4ffd71eec59a1fb71589104e2601bf634cd066c288751

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-4.31-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e5bf38f464ba420780734ce1ed7b6ec396974458afbce698d63624727f0858e2
MD5 eca61a8489fa67cab676635688ec4589
BLAKE2b-256 570e4e638321926f30f768a69bf72d7938b80a4f3ed4caac89cfb012cf41c72a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-4.31-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2a3762ff2ec4d413bf5ae97169d090ab8dc96becdf54d2b465711aa2b0e47e21
MD5 cb24846f58cacdfb7ac8b409ddc19ea4
BLAKE2b-256 0273d7cc9e7bb5477742ac160da6a1c944ba3a3e07c78d93c90ebf59fd103d29

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-4.31-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 18b4be70fffa7291c4058bf98ed1bd3309f8be8131c382811dd83a5f3122a4ff
MD5 af609deaeb50d815bcaaa3168729151d
BLAKE2b-256 8125315a9542719f0821fa766f132dce423169845e9ee87f646d5428714596c0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linearmodels-4.31-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 cb05a791250d6366099b14e9ad4ba9bb4fab5c2865dbedc4195feb599e17f699
MD5 3ae5f5e5c2b9ded94253c3167d09bb71
BLAKE2b-256 0fb14001292096bda951dd8753cc64f7bafada690522b91bb13699154d2c3fae

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