Linear Panel, Instrumental Variable, Asset Pricing, and System Regression models for Python
Project description
Linear Models
Metric | |
---|---|
Latest Release | |
Continuous Integration | |
Coverage | |
Code Quality | |
Citation |
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for linearmodels-5.1-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee2232ee69590fc3c1ea080debb1517210d14223e3d2eeca5667eae9b3608498 |
|
MD5 | 92ce2548ade7d223d42e01c39a66b36b |
|
BLAKE2b-256 | 674f126821439173b8be401e5db43808557ef75e89d5981b506e1f52b01c5d1e |
Hashes for linearmodels-5.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 456b673cf44d6964c261b188662db8aab94fd42748dd63b9eca8f9d5a1b7dbeb |
|
MD5 | 483cbcab9e3abdbceaad39b3ca8ce826 |
|
BLAKE2b-256 | 09bb41c831c184179c64a045abe312f63cf5633e2e28d3dde8b7b7044b6f2229 |
Hashes for linearmodels-5.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 766f99a2996b6558d16bc3b3a220a3c1de5d0c58c403c0fd62a15f2d4c491100 |
|
MD5 | 55a21c278effe8bc14c775df78ad70d7 |
|
BLAKE2b-256 | 9fcf735eb174b2e6f8c5a40a85be4bd3b79e38bbcf7f0a324ab832d5fb78d5b3 |
Hashes for linearmodels-5.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21e50a7addd23dcda7d5c64bf18911d4dcb7becb857576fc413969984b1105f2 |
|
MD5 | 1623ed032b8b968dd385d7da392b8f62 |
|
BLAKE2b-256 | 248f6c8835dda36df104ab741f63aaf65b4e40fe536d3f302382da1bd9f9fb90 |
Hashes for linearmodels-5.1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d208b14c1d6c548f39687a238f0897de31b64ed10acdb4af68825c52a3463b7 |
|
MD5 | 89cb89e6ab834e1b3a8b32a5aaa4e61f |
|
BLAKE2b-256 | 9d159777f937de4f68acc0439a6cffaa560f4f141e5e79630b4260baf2efd1b4 |
Hashes for linearmodels-5.1-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 771fa49dd2ad2cdca23af03dc9991080efc13724518853d808d1eec269de0c18 |
|
MD5 | ae96b5c962cc3102053e8e8459e679d7 |
|
BLAKE2b-256 | 4323f3f5eb9badcb5fe461d40a0432a9f8b1d501250803205df80c50c9776c69 |
Hashes for linearmodels-5.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9c95a316b022b631b636bb674652a15de6920f8a71d07dad1e9eabc4439f750 |
|
MD5 | adb789c080b87e9cf0bc006608d06c67 |
|
BLAKE2b-256 | fb548c1afbdb2c53b6706e05b3f4c1c3e0b2f1e8f761c4d0b331a8478771fc5c |
Hashes for linearmodels-5.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f77e90794468a7170b11b32d52cf6f4613e9dde056c986469ea61b49295a65d0 |
|
MD5 | 371f25502aed9bc893e97498c5860024 |
|
BLAKE2b-256 | 241e417d2df97ac1b50714a7106e4c50488b7fbb0e33562216f7367f471ae550 |
Hashes for linearmodels-5.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 985ecd9673880aded605ae7a52fc0a36e8e8d8dcedff82cd44f28cf091a23e12 |
|
MD5 | 5a9453ecb292d1657ad713e8fd2fbd1a |
|
BLAKE2b-256 | a2975ee7c355fa4ad615bea783eeed0c918635731ca79e9a427339bcea06ac32 |
Hashes for linearmodels-5.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c382600686089a4a70f185b8e557e1f124c5f2a538490ad301fc46f6838550f9 |
|
MD5 | 56960470ba5a266fde2c437fb8931d81 |
|
BLAKE2b-256 | b954c50f838be04167506aaecf400329bd1c3c4656790e51e23d2961ca25623b |
Hashes for linearmodels-5.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92c656f440cadeabd3b7a001b928623d131f8994cbe3deb37b537596fe391985 |
|
MD5 | fef79d45f8ae93a655c642435d3b86d6 |
|
BLAKE2b-256 | 1652ab08649cf31a6f7dc845c1a98b6e75fcc2395fb7fe7ee6b388a91a797001 |
Hashes for linearmodels-5.1-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 541d0fbd5795c915e07cf605d1ff6784f0b1c3ec61616267f5dee27606a56a12 |
|
MD5 | b35a4aef041eb71640158ff41c1a5b13 |
|
BLAKE2b-256 | c59f11c887dd25c88a359da09630b4fdce9042924022f0a3efc52f1779b0bb86 |
Hashes for linearmodels-5.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 780924735bed65dc13f88de5a21e44d500cb032b163b6b0c57f37af16903de5d |
|
MD5 | cc3b48b8b6ac0d9180f9c126f3f865c5 |
|
BLAKE2b-256 | 2b0b68e8758c255e50ee2b2b4fed53b029b27ef80dc528464768d3d60e3e5af4 |
Hashes for linearmodels-5.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 595170a19e59d11d06bc01f6b101a540ce5a1fc6be03831febb30d20cbd2262e |
|
MD5 | 3b6289149adef485d018202e65015b59 |
|
BLAKE2b-256 | 437dd5f6761500224d62f8fb5253b1d40f245e0c06e0c2349de7d4d7123235e8 |
Hashes for linearmodels-5.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6cc63b9405ab885fe6e04ef92aa10494188c17882c05860ef54d2199e6dc01d2 |
|
MD5 | 2736bfd531584c86c74d2bcf0bb95db0 |
|
BLAKE2b-256 | 02b16e40b2ca1fc8b6374145265562d3a0e5df04a04b6ea686e0317a1eaa4c9b |
Hashes for linearmodels-5.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8497767f217e590f2e355e09359ac36c25c2c72700f6f41708dd74930b4b839f |
|
MD5 | 4010ffe7df51bc57839b932536f1bb6d |
|
BLAKE2b-256 | f7526950bb4fa6728945dc8f9fea2b524f111d6cf07539df6d67374eef4acaf3 |