Skip to main content

Linear Models

Build Status codecov

Linear (regression) models for Python. Extends statsmodels to include Panel regression and instrumental variable estimators:

  • Panel regression with fixed effects (maximum two-way)

  • First difference regression

  • Between estimator for panel data

  • Pooled regression for panel data

  • Two-stage Least Squares

  • Limited Information Maximum Likelihood

  • k-class Estimators

  • Generalized Method of Moments, also with continuously updating

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_effect=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 + EntityEffect', 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

Documentation is automatically built using doctr on every successful build of master. The documentation is still rough but should improve quickly.

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 - not started

  • Linear IV Panel model estimation - not started

  • System regression - not started

Requirements

Running

With the exception of Python 3.5+, 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.5+: extensive use of @ operator

  • NumPy (1.11+)

  • SciPy (0.17+)

  • Pandas (0.19+)

  • xarray (0.9+)

  • Statsmodels (0.8+)

Testing

  • py.test

Documentation

  • sphinx

  • sphinx_rtd_theme

  • nbsphinx

  • nbconvert

  • nbformat

  • ipython

  • jupyter

Metadata

Release files for linearmodels 2.0

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

Built distribution (wheel)

Table of built distributions (wheels) for linearmodels 2.0
File Interpreter ABI Platform Actions
linearmodels-2.0-py2.py3-none-any.whl Python 3, Python 2 none any Details for linearmodels-2.0-py2.py3-none-any.whl

Release files / linearmodels-2.0-py2.py3-none-any.whl

Download URL linearmodels-2.0-py2.py3-none-any.whl
Size 881.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
439ac535d2170d0bcf097b94dd3cb2f85b362a514416518246f97e539ff0cb10
BLAKE2b-256 checksum
How to use checksums
451e46a68d85c8ceda01c53b730cc91e7663bc1012c228513ed6460cafd3c9a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for linearmodels 2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.0 This release

1 release file No provenance

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