Skip to main content

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

Release files for linearmodels 5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for linearmodels 5.0
File Size Uploaded
linearmodels-5.0.tar.gz 1.8 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for linearmodels 5.0
File
linearmodels-5.0-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
linearmodels-5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details
linearmodels-5.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ ARM64 Details
linearmodels-5.0-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
linearmodels-5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details
linearmodels-5.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ ARM64 Details
linearmodels-5.0-cp39-cp39-win_amd64.whl CPython 3.9 CPython 3.9 Windows x86-64 Details
linearmodels-5.0-cp39-cp39-win32.whl CPython 3.9 CPython 3.9 Windows x86-32 Details
linearmodels-5.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64 Details
linearmodels-5.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ ARM64 Details

Total release size: 20.4 MB

Release files / linearmodels-5.0.tar.gz

Download URL linearmodels-5.0.tar.gz
Size 1.8 MB
Tags Source
SHA-256 checksum
How to use checksums
2642be561fedbd9351479f9c1587e02bb3ff4972954044e5353a9bcfa8d366a9
BLAKE2b-256 checksum
How to use checksums
1d65b7d0f624af7c74c6d9d28cca9f1ff8e62a8585a867c9f51f41520e2bfb75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.12

Release files / linearmodels-5.0-cp311-cp311-win_amd64.whl

Download URL linearmodels-5.0-cp311-cp311-win_amd64.whl
Size 1.9 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
f76e52c567782ab8eabcece3efe4c27a7f7687bcd3db102a9c3e6866e39111d9
BLAKE2b-256 checksum
How to use checksums
3af397776a3a3d4e1686a5726aa8494f640b06e977c7fb1b89963df1b67b3aa2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release files / linearmodels-5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL linearmodels-5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.8 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
add65bcd6f118ab84ec08219207ebf54d8a3e6d3a18785f1b013a65744bccb49
BLAKE2b-256 checksum
How to use checksums
c05eb7e230b25f548b4f4214bbd15ba011ed58234c29be7bae283dfd20215554
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release files / linearmodels-5.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL linearmodels-5.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 1.8 MB
Tags CPython 3.11 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
6740ff846f4b418c4efd2346477a5afe79ea8f822bfbb2f66a33ac5518969d5a
BLAKE2b-256 checksum
How to use checksums
2f9737538a8c755db0838daf1ae4ae82af2185c4ceb43d8261bca857611daff0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release files / linearmodels-5.0-cp310-cp310-win_amd64.whl

Download URL linearmodels-5.0-cp310-cp310-win_amd64.whl
Size 1.9 MB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
f16c9375a46eaf344cfbae2ce4532a67196d2b8f60edb55fa93b748101978b33
BLAKE2b-256 checksum
How to use checksums
897b513353970d09429ba1dad7081b596eb28e3128a3ed992dba79e8f87b6cd8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release files / linearmodels-5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL linearmodels-5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.8 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
36c0e55407180491676eeac1242e28b6463af931f3429c27d901d81d277770a6
BLAKE2b-256 checksum
How to use checksums
c5214c14d67482098228f4ddea869113cc208a5f5e3e3fe0706923f69d2d884e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release files / linearmodels-5.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL linearmodels-5.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 1.8 MB
Tags CPython 3.10 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
f0888fea1cbfc6094a360d7fe17e9fe31862148c9751bb6a0e6e6180baf10a6c
BLAKE2b-256 checksum
How to use checksums
f405259ea9442635ba5a4bce6a19b868074ece71b13472f79af40d1c8f99d5b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release files / linearmodels-5.0-cp39-cp39-win_amd64.whl

Download URL linearmodels-5.0-cp39-cp39-win_amd64.whl
Size 1.9 MB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
13122d62601950f111df22ced5a5030e1a98adb0b06fa3266b6d67d3cac4c016
BLAKE2b-256 checksum
How to use checksums
84f4854e923b08e6c9d9afa676143c273676cd929b9d5db9996421f308696826
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release files / linearmodels-5.0-cp39-cp39-win32.whl

Download URL linearmodels-5.0-cp39-cp39-win32.whl
Size 1.9 MB
Tags CPython 3.9 Windows x86-32
SHA-256 checksum
How to use checksums
ace246e14b9a1bcd036e001307aae03648f2f573aa5c4e8fee85dc47bde5b114
BLAKE2b-256 checksum
How to use checksums
6eaef269e1bb254aaf692930ce2655e069d0f709de9009309dbf2d49443f6991
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release files / linearmodels-5.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL linearmodels-5.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.8 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
1446e8db914f538dc1f6e3b77aa7c4cc4553e6405218b6d694de5ce1f35a5979
BLAKE2b-256 checksum
How to use checksums
4a4545dd9bcc7af295abb5ff7a8cc685562ba31db0b09a5954e4263f39229a07
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release files / linearmodels-5.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL linearmodels-5.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 1.8 MB
Tags CPython 3.9 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
9a39e504b98ae82813649e7d7369e8a21525b66773a01e7fe493114080acf1b6
BLAKE2b-256 checksum
How to use checksums
0062f580958e8ce711e26b3757f76fb56651c981349b1a3b2f4aeafd29822bff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release history Release notifications | RSS feed

7.0

31 release files

6.1

30 release files

6.0

25 release files

5.4

25 release files

5.3

29 release files

5.2

17 release files

5.1

17 release files

This release

5.0 This release

11 release files

4.31

23 release files

4.30

23 release files

4.29

23 release files

4.28

23 release files

4.27

18 release files

4.26

18 release files

4.25

23 release files

4.24

16 release files

4.23

16 release files

4.22

16 release files

4.21

16 release files

4.20

16 release files

4.19

16 release files

4.18

7 release files

4.17

16 release files

4.16

16 release files

4.15.2

1 release file

4.15

3 release files

4.14

2 release files

4.13

1 release file

4.12

1 release file

4.11

1 release file

4.10

2 release files

4.9

2 release files

4.8

2 release files

4.7

2 release files

4.6

2 release files

4.5

2 release files

4.2

2 release files

4.1

2 release files

3.5

2 release files

3.0

1 release file

2.0

1 release file

1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page