Skip to main content

Linear Models

Build Status codecov Codacy Badge codebeat badge Code Quality: Python Total Alerts

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 patsy 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.

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 master branch can be installed by cloning the repo and running setup

git clone https://github.com/bashtage/linearmodels
cd linearmodels
python setup.py install

Documentation

Stable Documentation is built on every tagged version using doctr. Development Documentation is automatically built on every successful build of master.

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.6+, 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.6+

  • NumPy (1.14+)

  • SciPy (1+)

  • pandas (0.22+)

  • statsmodels (0.9+)

  • xarray (0.9+, optional)

  • cython (optional)

Testing

  • py.test

Documentation

  • sphinx

  • sphinx-material

  • nbsphinx

  • nbconvert

  • nbformat

  • ipython

  • jupyter

Metadata

Release files for linearmodels 4.15.4

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 4.15.4
File Size Uploaded
linearmodels-4.15.4.tar.gz 1.7 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for linearmodels 4.15.4
File
linearmodels-4.15.4-cp38-cp38-win_amd64.whl CPython 3.8 CPython 3.8 Windows x86-64 Details
linearmodels-4.15.4-cp38-cp38-win32.whl CPython 3.8 CPython 3.8 Windows x86-32 Details
linearmodels-4.15.4-cp38-cp38-manylinux1_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.5+ x86-64 Details
linearmodels-4.15.4-cp38-cp38-manylinux1_i686.whl CPython 3.8 CPython 3.8 Linux glibc 2.5+ x86-32 Details
linearmodels-4.15.4-cp38-cp38-macosx_10_9_x86_64.whl CPython 3.8 CPython 3.8 macOS 10.9+ x86-64 Details
linearmodels-4.15.4-cp37-cp37m-win_amd64.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-64 Details
linearmodels-4.15.4-cp37-cp37m-win32.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-32 Details
linearmodels-4.15.4-cp37-cp37m-manylinux1_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-64 Details
linearmodels-4.15.4-cp37-cp37m-manylinux1_i686.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-32 Details
linearmodels-4.15.4-cp37-cp37m-macosx_10_9_x86_64.whl CPython 3.7 CPython 3.7 pymalloc macOS 10.9+ x86-64 Details
linearmodels-4.15.4-cp36-cp36m-win_amd64.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-64 Details
linearmodels-4.15.4-cp36-cp36m-win32.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-32 Details
linearmodels-4.15.4-cp36-cp36m-manylinux1_x86_64.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64 Details
linearmodels-4.15.4-cp36-cp36m-manylinux1_i686.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-32 Details
linearmodels-4.15.4-cp36-cp36m-macosx_10_9_x86_64.whl CPython 3.6 CPython 3.6 pymalloc macOS 10.9+ x86-64 Details

Total release size: 24.1 MB

Release files / linearmodels-4.15.4.tar.gz

Download URL linearmodels-4.15.4.tar.gz
Size 1.7 MB
Tags Source
SHA-256 checksum
How to use checksums
ac720fb2111fcfee27638e284d50f719a163cf885ab167f7936fcf3d4d68f7b9
BLAKE2b-256 checksum
How to use checksums
770765fcdd7d20beab6a4b14ef5f34f116fd82140df95840dcac69d676592ffc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0.post20200106 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.6

Release files / linearmodels-4.15.4-cp38-cp38-win_amd64.whl

Download URL linearmodels-4.15.4-cp38-cp38-win_amd64.whl
Size 1.6 MB
Tags CPython 3.8 Windows x86-64
SHA-256 checksum
How to use checksums
67b69cc574f86989fbd6b93f39436c00abbf09363c35679872ca7eee6fb8278f
BLAKE2b-256 checksum
How to use checksums
77468abe5105a7935c751a8ada2fc36e3ef75d644d16e0f3d48b3b3fdb0d26ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.0

Release files / linearmodels-4.15.4-cp38-cp38-win32.whl

Download URL linearmodels-4.15.4-cp38-cp38-win32.whl
Size 1.6 MB
Tags CPython 3.8 Windows x86-32
SHA-256 checksum
How to use checksums
3c1601708386f16f03fd81dbb00a6ce6fad4fa6185d8480a6a6a8f57f3425591
BLAKE2b-256 checksum
How to use checksums
12181d429f4d61ae4825dde39fc1251e4cdf2a132e6bcd1dfb6f4a48a8955c0e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.0

Release files / linearmodels-4.15.4-cp38-cp38-manylinux1_x86_64.whl

Download URL linearmodels-4.15.4-cp38-cp38-manylinux1_x86_64.whl
Size 1.5 MB
Tags CPython 3.8 Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
9f7399083910715e7c17ce1eaa6ec77628c51eaf11817ec0ce796a2af1b43066
BLAKE2b-256 checksum
How to use checksums
533c118ea51c8f62f0829874200c8249ff245bf03d1c028db7c41b2ed1bfd896
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/2.7.12

Release files / linearmodels-4.15.4-cp38-cp38-manylinux1_i686.whl

Download URL linearmodels-4.15.4-cp38-cp38-manylinux1_i686.whl
Size 1.4 MB
Tags CPython 3.8 Linux glibc 2.5+ x86-32
SHA-256 checksum
How to use checksums
425becece297e777c7e0e28341c33eb07a06841f74c05ed528ae55b400ef3c36
BLAKE2b-256 checksum
How to use checksums
f18a04d6ac3c071c61a4b001dd5b50cef61ecd885261d57324cdeb519feca646
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/2.7.12

Release files / linearmodels-4.15.4-cp38-cp38-macosx_10_9_x86_64.whl

Download URL linearmodels-4.15.4-cp38-cp38-macosx_10_9_x86_64.whl
Size 1.4 MB
Tags CPython 3.8 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
41b151722b9aa750c041991592648f376dc91a7f0863b3068a0b3d9457df84c4
BLAKE2b-256 checksum
How to use checksums
a6537d9610f665e33adf55be0bbfef85d2235454579b19d4f15df8946b39bac5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.6.8

Release files / linearmodels-4.15.4-cp37-cp37m-win_amd64.whl

Download URL linearmodels-4.15.4-cp37-cp37m-win_amd64.whl
Size 1.6 MB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
b6385c4fdc2e694b94c9e50ae7725ef7c9485f2891f1a7c12976f8dbcb431909
BLAKE2b-256 checksum
How to use checksums
9f3ff2a74b27554c58ea37273e91e3d2879fef6e35e8343ca2be706959acee04
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.5

Release files / linearmodels-4.15.4-cp37-cp37m-win32.whl

Download URL linearmodels-4.15.4-cp37-cp37m-win32.whl
Size 1.6 MB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
a0036306a57f3d2a5114c47aa480a1e0238bc5a5536cfac035f8d2738e833100
BLAKE2b-256 checksum
How to use checksums
c284868c4016d8b79cd421b3545bc8ddd49fc561d6485bb67180e6895f5025e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.5

Release files / linearmodels-4.15.4-cp37-cp37m-manylinux1_x86_64.whl

Download URL linearmodels-4.15.4-cp37-cp37m-manylinux1_x86_64.whl
Size 1.5 MB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
50c55189ad2d1abd544368143f49ae9528b2ecd5b1e21614790bd8ab28b4f71d
BLAKE2b-256 checksum
How to use checksums
4a0def8f2208b6e7d668d0adad774c7015020a2a8002b253910cbed1b359c7c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/2.7.12

Release files / linearmodels-4.15.4-cp37-cp37m-manylinux1_i686.whl

Download URL linearmodels-4.15.4-cp37-cp37m-manylinux1_i686.whl
Size 1.4 MB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-32
SHA-256 checksum
How to use checksums
4f57c0ecdb76eec4a459f0063b6260a064b2caac5360091a4034871643b9fd7c
BLAKE2b-256 checksum
How to use checksums
508a95817c54c53dd2e619009f2f8ab5a8c1b1d00c8ae2026a63ed07e1176441
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/2.7.12

Release files / linearmodels-4.15.4-cp37-cp37m-macosx_10_9_x86_64.whl

Download URL linearmodels-4.15.4-cp37-cp37m-macosx_10_9_x86_64.whl
Size 1.4 MB
Tags CPython 3.7 CPython 3.7 pymalloc macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
aea48559b31abc3b679bc4aba770bbe20ef7e181274a7a1c0fa4a27b8b5c4b88
BLAKE2b-256 checksum
How to use checksums
8a07fa3eac345aa9afb5a177a10ef0864a687a4a3b0827f5f9d95a57ab17da7d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.6.8

Release files / linearmodels-4.15.4-cp36-cp36m-win_amd64.whl

Download URL linearmodels-4.15.4-cp36-cp36m-win_amd64.whl
Size 1.6 MB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
c89b89186afb309bceead3f68ac1b3554332ac8681e88541af460ae75cc043df
BLAKE2b-256 checksum
How to use checksums
fcceeb057a7886ea55e34c41f0d0846c6efa62ee4731aeee623e53da868dbf28
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.6.8

Release files / linearmodels-4.15.4-cp36-cp36m-win32.whl

Download URL linearmodels-4.15.4-cp36-cp36m-win32.whl
Size 1.6 MB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
e79694f1ae850dde727df25f46ed771f82f1d5293d2d42af4901f48fd1b7a8f8
BLAKE2b-256 checksum
How to use checksums
4d4776bf8a92a02d6ed4e3b7f63ee3eeeb3014e64842f183430088605e014f46
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.6.8

Release files / linearmodels-4.15.4-cp36-cp36m-manylinux1_x86_64.whl

Download URL linearmodels-4.15.4-cp36-cp36m-manylinux1_x86_64.whl
Size 1.5 MB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
0ff784193c6c8cf84bb2fea34c2ff61eb2db6b2acbd37296903e900efddf9c3f
BLAKE2b-256 checksum
How to use checksums
27651c16abb6e2364d6bc002d8aad09bc4096b05eb5dc14117cf006ebd6c935c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/2.7.12

Release files / linearmodels-4.15.4-cp36-cp36m-manylinux1_i686.whl

Download URL linearmodels-4.15.4-cp36-cp36m-manylinux1_i686.whl
Size 1.4 MB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-32
SHA-256 checksum
How to use checksums
76db2e0e53b0223a9ef11b8604ec55dca3cc1a55cd31ab750b0a437f93d99153
BLAKE2b-256 checksum
How to use checksums
b29b8dfca590c428f3405243b7d341e9beb58486597d6e1d96897af74822fc28
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/2.7.12

Release files / linearmodels-4.15.4-cp36-cp36m-macosx_10_9_x86_64.whl

Download URL linearmodels-4.15.4-cp36-cp36m-macosx_10_9_x86_64.whl
Size 1.4 MB
Tags CPython 3.6 CPython 3.6 pymalloc macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
f02690aebcc7d851721d920fc2f38555034fa5ef1a1b0526d1dc9250e65466cd
BLAKE2b-256 checksum
How to use checksums
dea2cbbd856e9549c59a54f1e5ad0252857843fa1625934bcb31f5dd4faaf458
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.6.8

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

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

This release

4.15.4 This release

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