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

Metadata

Release files for linearmodels 5.1

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.1
File Size Uploaded
linearmodels-5.1.tar.gz 1.8 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for linearmodels 5.1
File
linearmodels-5.1-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
linearmodels-5.1-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.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ ARM64 Details
linearmodels-5.1-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details
linearmodels-5.1-cp311-cp311-macosx_10_9_x86_64.whl CPython 3.11 CPython 3.11 macOS 10.9+ x86-64 Details
linearmodels-5.1-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
linearmodels-5.1-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.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ ARM64 Details
linearmodels-5.1-cp310-cp310-macosx_11_0_arm64.whl CPython 3.10 CPython 3.10 macOS 11.0+ ARM64 Details
linearmodels-5.1-cp310-cp310-macosx_10_9_x86_64.whl CPython 3.10 CPython 3.10 macOS 10.9+ x86-64 Details
linearmodels-5.1-cp39-cp39-win_amd64.whl CPython 3.9 CPython 3.9 Windows x86-64 Details
linearmodels-5.1-cp39-cp39-win32.whl CPython 3.9 CPython 3.9 Windows x86-32 Details
linearmodels-5.1-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.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ ARM64 Details
linearmodels-5.1-cp39-cp39-macosx_11_0_arm64.whl CPython 3.9 CPython 3.9 macOS 11.0+ ARM64 Details
linearmodels-5.1-cp39-cp39-macosx_10_9_x86_64.whl CPython 3.9 CPython 3.9 macOS 10.9+ x86-64 Details

Total release size: 31.2 MB

Release files / linearmodels-5.1.tar.gz

Download URL linearmodels-5.1.tar.gz
Size 1.8 MB
Tags Source
SHA-256 checksum
How to use checksums
1a157a974a346a78b9a3e42b86e5a624b052c4269b0441f56deac57f75cf95c5
BLAKE2b-256 checksum
How to use checksums
a587eb104406ba446508e1d44ff6e71584e02ed5719d725ee4e4ab9591bfcbe7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.11

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

Download URL linearmodels-5.1-cp311-cp311-win_amd64.whl
Size 1.9 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
ee2232ee69590fc3c1ea080debb1517210d14223e3d2eeca5667eae9b3608498
BLAKE2b-256 checksum
How to use checksums
674f126821439173b8be401e5db43808557ef75e89d5981b506e1f52b01c5d1e
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.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL linearmodels-5.1-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
456b673cf44d6964c261b188662db8aab94fd42748dd63b9eca8f9d5a1b7dbeb
BLAKE2b-256 checksum
How to use checksums
09bb41c831c184179c64a045abe312f63cf5633e2e28d3dde8b7b7044b6f2229
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.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL linearmodels-5.1-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
766f99a2996b6558d16bc3b3a220a3c1de5d0c58c403c0fd62a15f2d4c491100
BLAKE2b-256 checksum
How to use checksums
9fcf735eb174b2e6f8c5a40a85be4bd3b79e38bbcf7f0a324ab832d5fb78d5b3
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.1-cp311-cp311-macosx_11_0_arm64.whl

Download URL linearmodels-5.1-cp311-cp311-macosx_11_0_arm64.whl
Size 1.8 MB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
21e50a7addd23dcda7d5c64bf18911d4dcb7becb857576fc413969984b1105f2
BLAKE2b-256 checksum
How to use checksums
248f6c8835dda36df104ab741f63aaf65b4e40fe536d3f302382da1bd9f9fb90
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.1-cp311-cp311-macosx_10_9_x86_64.whl

Download URL linearmodels-5.1-cp311-cp311-macosx_10_9_x86_64.whl
Size 1.8 MB
Tags CPython 3.11 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
2d208b14c1d6c548f39687a238f0897de31b64ed10acdb4af68825c52a3463b7
BLAKE2b-256 checksum
How to use checksums
9d159777f937de4f68acc0439a6cffaa560f4f141e5e79630b4260baf2efd1b4
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.1-cp310-cp310-win_amd64.whl

Download URL linearmodels-5.1-cp310-cp310-win_amd64.whl
Size 1.9 MB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
771fa49dd2ad2cdca23af03dc9991080efc13724518853d808d1eec269de0c18
BLAKE2b-256 checksum
How to use checksums
4323f3f5eb9badcb5fe461d40a0432a9f8b1d501250803205df80c50c9776c69
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.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL linearmodels-5.1-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
f9c95a316b022b631b636bb674652a15de6920f8a71d07dad1e9eabc4439f750
BLAKE2b-256 checksum
How to use checksums
fb548c1afbdb2c53b6706e05b3f4c1c3e0b2f1e8f761c4d0b331a8478771fc5c
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.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL linearmodels-5.1-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
f77e90794468a7170b11b32d52cf6f4613e9dde056c986469ea61b49295a65d0
BLAKE2b-256 checksum
How to use checksums
241e417d2df97ac1b50714a7106e4c50488b7fbb0e33562216f7367f471ae550
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.1-cp310-cp310-macosx_11_0_arm64.whl

Download URL linearmodels-5.1-cp310-cp310-macosx_11_0_arm64.whl
Size 1.8 MB
Tags CPython 3.10 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
985ecd9673880aded605ae7a52fc0a36e8e8d8dcedff82cd44f28cf091a23e12
BLAKE2b-256 checksum
How to use checksums
a2975ee7c355fa4ad615bea783eeed0c918635731ca79e9a427339bcea06ac32
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.1-cp310-cp310-macosx_10_9_x86_64.whl

Download URL linearmodels-5.1-cp310-cp310-macosx_10_9_x86_64.whl
Size 1.8 MB
Tags CPython 3.10 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
c382600686089a4a70f185b8e557e1f124c5f2a538490ad301fc46f6838550f9
BLAKE2b-256 checksum
How to use checksums
b954c50f838be04167506aaecf400329bd1c3c4656790e51e23d2961ca25623b
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.1-cp39-cp39-win_amd64.whl

Download URL linearmodels-5.1-cp39-cp39-win_amd64.whl
Size 1.9 MB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
92c656f440cadeabd3b7a001b928623d131f8994cbe3deb37b537596fe391985
BLAKE2b-256 checksum
How to use checksums
1652ab08649cf31a6f7dc845c1a98b6e75fcc2395fb7fe7ee6b388a91a797001
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.1-cp39-cp39-win32.whl

Download URL linearmodels-5.1-cp39-cp39-win32.whl
Size 1.9 MB
Tags CPython 3.9 Windows x86-32
SHA-256 checksum
How to use checksums
541d0fbd5795c915e07cf605d1ff6784f0b1c3ec61616267f5dee27606a56a12
BLAKE2b-256 checksum
How to use checksums
c59f11c887dd25c88a359da09630b4fdce9042924022f0a3efc52f1779b0bb86
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.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL linearmodels-5.1-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
780924735bed65dc13f88de5a21e44d500cb032b163b6b0c57f37af16903de5d
BLAKE2b-256 checksum
How to use checksums
2b0b68e8758c255e50ee2b2b4fed53b029b27ef80dc528464768d3d60e3e5af4
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.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL linearmodels-5.1-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
595170a19e59d11d06bc01f6b101a540ce5a1fc6be03831febb30d20cbd2262e
BLAKE2b-256 checksum
How to use checksums
437dd5f6761500224d62f8fb5253b1d40f245e0c06e0c2349de7d4d7123235e8
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.1-cp39-cp39-macosx_11_0_arm64.whl

Download URL linearmodels-5.1-cp39-cp39-macosx_11_0_arm64.whl
Size 1.8 MB
Tags CPython 3.9 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
6cc63b9405ab885fe6e04ef92aa10494188c17882c05860ef54d2199e6dc01d2
BLAKE2b-256 checksum
How to use checksums
02b16e40b2ca1fc8b6374145265562d3a0e5df04a04b6ea686e0317a1eaa4c9b
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.1-cp39-cp39-macosx_10_9_x86_64.whl

Download URL linearmodels-5.1-cp39-cp39-macosx_10_9_x86_64.whl
Size 1.8 MB
Tags CPython 3.9 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
8497767f217e590f2e355e09359ac36c25c2c72700f6f41708dd74930b4b839f
BLAKE2b-256 checksum
How to use checksums
f7526950bb4fa6728945dc8f9fea2b524f111d6cf07539df6d67374eef4acaf3
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

This release

5.1 This release

17 release files

5.0

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