# Linear Models
| Metric | |
| :------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Latest Release** | [![PyPI version](https://badge.fury.io/py/linearmodels.svg)](https://badge.fury.io/py/linearmodels) |
| **Continuous Integration** | [![Build Status](https://dev.azure.com/kevinksheppard/kevinksheppard/_apis/build/status/bashtage.linearmodels?branchName=main)](https://dev.azure.com/kevinksheppard/kevinksheppard/_build/latest?definitionId=2&branchName=main) |
| **Coverage** | [![codecov](https://codecov.io/gh/bashtage/linearmodels/branch/main/graph/badge.svg)](https://codecov.io/gh/bashtage/linearmodels) |
| **Code Quality** | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/745a24a69cb2466b95df6a53c83892de)](https://www.codacy.com/manual/bashtage/linearmodels?utm_source=github.com&utm_medium=referral&utm_content=bashtage/linearmodels&utm_campaign=Badge_Grade) |
| | [![codebeat badge](https://codebeat.co/badges/aaae2fb4-72b5-4a66-97cd-77b93488f243)](https://codebeat.co/projects/github-com-bashtage-linearmodels-main) |
| **Citation** | [![DOI](https://zenodo.org/badge/82291672.svg)](https://zenodo.org/badge/latestdoi/82291672) |
Linear (regression) models for Python. Extends
[statsmodels](http://www.statsmodels.org) 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](http://www.statsmodels.org) to include, supports
formulas for specifying models. For example, the classic Grunfeld regression can be
specified
```python
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.
```python
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](https://github.com/matthewwardrop/formulaic/)
package which is a replacement for [patsy](https://patsy.readthedocs.io/en/latest/).
## Instrumental Variable Models
IV regression models can be similarly specified.
```python
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
```bash
pip install linearmodels
```
The main branch can be installed by cloning the repo and running setup
```bash
git clone https://github.com/bashtage/linearmodels
cd linearmodels
pip install .
```
## Documentation
[Stable Documentation](https://bashtage.github.io/linearmodels/) is
built on every tagged version using
[doctr](https://github.com/drdoctr/doctr).
[Development Documentation](https://bashtage.github.io/linearmodels/devel)
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.22+)
- SciPy (1.8+)
- pandas (1.4+)
- statsmodels (0.12+)
- formulaic (1.0.0+)
- xarray (0.16+, optional)
- Cython (3.0.10+, optional)
### Testing
- py.test
### Documentation
- sphinx
- sphinx-immaterial
- nbsphinx
- nbconvert
- nbformat
- ipython
- jupyter
Raw data
{
"_id": null,
"home_page": "http://github.com/bashtage/linearmodels",
"name": "linearmodels",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "linear models, regression, instrumental variables, IV, panel, fixed effects, clustered, heteroskedasticity, endogeneity, instruments, statistics, statistical inference, econometrics",
"author": "Kevin Sheppard",
"author_email": "kevin.k.sheppard@gmail.com",
"download_url": null,
"platform": null,
"description": "# Linear Models\r\n\r\n| Metric | |\r\n| :------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\r\n| **Latest Release** | [![PyPI version](https://badge.fury.io/py/linearmodels.svg)](https://badge.fury.io/py/linearmodels) |\r\n| **Continuous Integration** | [![Build Status](https://dev.azure.com/kevinksheppard/kevinksheppard/_apis/build/status/bashtage.linearmodels?branchName=main)](https://dev.azure.com/kevinksheppard/kevinksheppard/_build/latest?definitionId=2&branchName=main) |\r\n| **Coverage** | [![codecov](https://codecov.io/gh/bashtage/linearmodels/branch/main/graph/badge.svg)](https://codecov.io/gh/bashtage/linearmodels) |\r\n| **Code Quality** | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/745a24a69cb2466b95df6a53c83892de)](https://www.codacy.com/manual/bashtage/linearmodels?utm_source=github.com&utm_medium=referral&utm_content=bashtage/linearmodels&utm_campaign=Badge_Grade) |\r\n| | [![codebeat badge](https://codebeat.co/badges/aaae2fb4-72b5-4a66-97cd-77b93488f243)](https://codebeat.co/projects/github-com-bashtage-linearmodels-main) |\r\n| **Citation** | [![DOI](https://zenodo.org/badge/82291672.svg)](https://zenodo.org/badge/latestdoi/82291672) |\r\n\r\nLinear (regression) models for Python. Extends\r\n[statsmodels](http://www.statsmodels.org) with Panel regression,\r\ninstrumental variable estimators, system estimators and models for\r\nestimating asset prices:\r\n\r\n- **Panel models**:\r\n - Fixed effects (maximum two-way)\r\n - First difference regression\r\n - Between estimator for panel data\r\n - Pooled regression for panel data\r\n - Fama-MacBeth estimation of panel models\r\n\r\n- **High-dimensional Regresssion**:\r\n - Absorbing Least Squares\r\n\r\n- **Instrumental Variable estimators**\r\n - Two-stage Least Squares\r\n - Limited Information Maximum Likelihood\r\n - k-class Estimators\r\n - Generalized Method of Moments, also with continuously updating\r\n\r\n- **Factor Asset Pricing Models**:\r\n - 2- and 3-step estimation\r\n - Time-series estimation\r\n - GMM estimation\r\n\r\n- **System Regression**:\r\n - Seemingly Unrelated Regression (SUR/SURE)\r\n - Three-Stage Least Squares (3SLS)\r\n - Generalized Method of Moments (GMM) System Estimation\r\n\r\nDesigned to work equally well with NumPy, Pandas or xarray data.\r\n\r\n## Panel models\r\n\r\nLike [statsmodels](http://www.statsmodels.org) to include, supports\r\nformulas for specifying models. For example, the classic Grunfeld regression can be\r\nspecified\r\n\r\n```python\r\nimport numpy as np\r\nfrom statsmodels.datasets import grunfeld\r\ndata = grunfeld.load_pandas().data\r\ndata.year = data.year.astype(np.int64)\r\n# MultiIndex, entity - time\r\ndata = data.set_index(['firm','year'])\r\nfrom linearmodels import PanelOLS\r\nmod = PanelOLS(data.invest, data[['value','capital']], entity_effects=True)\r\nres = mod.fit(cov_type='clustered', cluster_entity=True)\r\n```\r\n\r\nModels can also be specified using the formula interface.\r\n\r\n```python\r\nfrom linearmodels import PanelOLS\r\nmod = PanelOLS.from_formula('invest ~ value + capital + EntityEffects', data)\r\nres = mod.fit(cov_type='clustered', cluster_entity=True)\r\n```\r\n\r\nThe formula interface for `PanelOLS` supports the special values\r\n`EntityEffects` and `TimeEffects` which add entity (fixed) and time\r\neffects, respectively.\r\n\r\nFormula support comes from the [formulaic](https://github.com/matthewwardrop/formulaic/)\r\npackage which is a replacement for [patsy](https://patsy.readthedocs.io/en/latest/).\r\n\r\n## Instrumental Variable Models\r\n\r\nIV regression models can be similarly specified.\r\n\r\n```python\r\nimport numpy as np\r\nfrom linearmodels.iv import IV2SLS\r\nfrom linearmodels.datasets import mroz\r\ndata = mroz.load()\r\nmod = IV2SLS.from_formula('np.log(wage) ~ 1 + exper + exper ** 2 + [educ ~ motheduc + fatheduc]', data)\r\n```\r\n\r\nThe expressions in the `[ ]` indicate endogenous regressors (before `~`)\r\nand the instruments.\r\n\r\n## Installing\r\n\r\nThe latest release can be installed using pip\r\n\r\n```bash\r\npip install linearmodels\r\n```\r\n\r\nThe main branch can be installed by cloning the repo and running setup\r\n\r\n```bash\r\ngit clone https://github.com/bashtage/linearmodels\r\ncd linearmodels\r\npip install .\r\n```\r\n\r\n## Documentation\r\n\r\n[Stable Documentation](https://bashtage.github.io/linearmodels/) is\r\nbuilt on every tagged version using\r\n[doctr](https://github.com/drdoctr/doctr).\r\n[Development Documentation](https://bashtage.github.io/linearmodels/devel)\r\nis automatically built on every successful build of main.\r\n\r\n## Plan and status\r\n\r\nShould eventually add some useful linear model estimators such as panel\r\nregression. Currently only the single variable IV estimators are polished.\r\n\r\n- Linear Instrumental variable estimation - **complete**\r\n- Linear Panel model estimation - **complete**\r\n- Fama-MacBeth regression - **complete**\r\n- Linear Factor Asset Pricing - **complete**\r\n- System regression - **complete**\r\n- Linear IV Panel model estimation - _not started_\r\n- Dynamic Panel model estimation - _not started_\r\n\r\n## Requirements\r\n\r\n### Running\r\n\r\n- Python 3.9+\r\n- NumPy (1.22+)\r\n- SciPy (1.8+)\r\n- pandas (1.4+)\r\n- statsmodels (0.12+)\r\n- formulaic (1.0.0+)\r\n- xarray (0.16+, optional)\r\n- Cython (3.0.10+, optional)\r\n\r\n\r\n### Testing\r\n\r\n- py.test\r\n\r\n### Documentation\r\n\r\n- sphinx\r\n- sphinx-immaterial\r\n- nbsphinx\r\n- nbconvert\r\n- nbformat\r\n- ipython\r\n- jupyter\r\n",
"bugtrack_url": null,
"license": "NCSA",
"summary": "Linear Panel, Instrumental Variable, Asset Pricing, and System Regression models for Python",
"version": "6.0",
"project_urls": {
"Homepage": "http://github.com/bashtage/linearmodels"
},
"split_keywords": [
"linear models",
" regression",
" instrumental variables",
" iv",
" panel",
" fixed effects",
" clustered",
" heteroskedasticity",
" endogeneity",
" instruments",
" statistics",
" statistical inference",
" econometrics"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "7899784c4f2fb5c0cd9185cac4f5c263f5bdfc979a62cea09001563b2c68be9f",
"md5": "b00b29beddc8568197ac64017951c18c",
"sha256": "549c454d2fdece5c9af416b094030a34a992f93bc66d88624102dccb0aa9acb9"
},
"downloads": -1,
"filename": "linearmodels-6.0-cp310-cp310-macosx_10_9_x86_64.whl",
"has_sig": false,
"md5_digest": "b00b29beddc8568197ac64017951c18c",
"packagetype": "bdist_wheel",
"python_version": "cp310",
"requires_python": ">=3.9",
"size": 1498470,
"upload_time": "2024-04-16T17:42:06",
"upload_time_iso_8601": "2024-04-16T17:42:06.467594Z",
"url": "https://files.pythonhosted.org/packages/78/99/784c4f2fb5c0cd9185cac4f5c263f5bdfc979a62cea09001563b2c68be9f/linearmodels-6.0-cp310-cp310-macosx_10_9_x86_64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "23463614716897d7de4cdb4c06a4546edd56731a8f1014ac771643257734358b",
"md5": "d2c6f9ea1d0d4cb28deee2c0b4721317",
"sha256": "f6fd917592a798fbededb861801d73c79729f5d29334360a56c1fa9e5a192a69"
},
"downloads": -1,
"filename": "linearmodels-6.0-cp310-cp310-macosx_11_0_arm64.whl",
"has_sig": false,
"md5_digest": "d2c6f9ea1d0d4cb28deee2c0b4721317",
"packagetype": "bdist_wheel",
"python_version": "cp310",
"requires_python": ">=3.9",
"size": 1492817,
"upload_time": "2024-04-16T17:42:08",
"upload_time_iso_8601": "2024-04-16T17:42:08.868061Z",
"url": "https://files.pythonhosted.org/packages/23/46/3614716897d7de4cdb4c06a4546edd56731a8f1014ac771643257734358b/linearmodels-6.0-cp310-cp310-macosx_11_0_arm64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "0ec000656e1839dc5d90daf1f24a7082d30efdb435a97154ef3a84d6821b1df7",
"md5": "041212c6432a0f980c9916b327926875",
"sha256": "e0f1eae8a66d04e016c3c53e6f3e6ac4d66da1367a4c5ebd1f2670633aa8f3ee"
},
"downloads": -1,
"filename": "linearmodels-6.0-cp311-cp311-macosx_10_9_x86_64.whl",
"has_sig": false,
"md5_digest": "041212c6432a0f980c9916b327926875",
"packagetype": "bdist_wheel",
"python_version": "cp311",
"requires_python": ">=3.9",
"size": 1498211,
"upload_time": "2024-04-16T17:42:42",
"upload_time_iso_8601": "2024-04-16T17:42:42.430735Z",
"url": "https://files.pythonhosted.org/packages/0e/c0/00656e1839dc5d90daf1f24a7082d30efdb435a97154ef3a84d6821b1df7/linearmodels-6.0-cp311-cp311-macosx_10_9_x86_64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "5f7e4821d226b746b0c840e05d3acba271bb594b83651bb062f3b189e631676d",
"md5": "0acb0d85916dda5a94bafabbf8f4ee0a",
"sha256": "25f31d12a9ca41f8fca5da691f60ec0dfe1f199a7ea915785fd639bdd3177e08"
},
"downloads": -1,
"filename": "linearmodels-6.0-cp311-cp311-macosx_11_0_arm64.whl",
"has_sig": false,
"md5_digest": "0acb0d85916dda5a94bafabbf8f4ee0a",
"packagetype": "bdist_wheel",
"python_version": "cp311",
"requires_python": ">=3.9",
"size": 1492415,
"upload_time": "2024-04-16T17:42:44",
"upload_time_iso_8601": "2024-04-16T17:42:44.724914Z",
"url": "https://files.pythonhosted.org/packages/5f/7e/4821d226b746b0c840e05d3acba271bb594b83651bb062f3b189e631676d/linearmodels-6.0-cp311-cp311-macosx_11_0_arm64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "71cffdafe80ecb6ad016cb45e9405c9badc95d527520be13fa6515c271ef6fc8",
"md5": "de724dad773c9ff0dca4977967692979",
"sha256": "67f56c205ff6ce2c46229949f54d4775f010c3e768771ef5f02d8258367782dd"
},
"downloads": -1,
"filename": "linearmodels-6.0-cp311-cp311-win_amd64.whl",
"has_sig": false,
"md5_digest": "de724dad773c9ff0dca4977967692979",
"packagetype": "bdist_wheel",
"python_version": "cp311",
"requires_python": ">=3.9",
"size": 1658031,
"upload_time": "2024-04-16T17:42:39",
"upload_time_iso_8601": "2024-04-16T17:42:39.645786Z",
"url": "https://files.pythonhosted.org/packages/71/cf/fdafe80ecb6ad016cb45e9405c9badc95d527520be13fa6515c271ef6fc8/linearmodels-6.0-cp311-cp311-win_amd64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "70912ce4142d9340dce8b85ff5162b9ed01b25bfbaf2952923ef3d77daa3418d",
"md5": "9f0d1a10785763d054be45fb9d0fa8a2",
"sha256": "106b63ebe63dbcba31ae0170fefbded2e447340079e448e53263a5b88f2d986e"
},
"downloads": -1,
"filename": "linearmodels-6.0-cp39-cp39-macosx_10_9_x86_64.whl",
"has_sig": false,
"md5_digest": "9f0d1a10785763d054be45fb9d0fa8a2",
"packagetype": "bdist_wheel",
"python_version": "cp39",
"requires_python": ">=3.9",
"size": 1499054,
"upload_time": "2024-04-16T17:43:08",
"upload_time_iso_8601": "2024-04-16T17:43:08.552093Z",
"url": "https://files.pythonhosted.org/packages/70/91/2ce4142d9340dce8b85ff5162b9ed01b25bfbaf2952923ef3d77daa3418d/linearmodels-6.0-cp39-cp39-macosx_10_9_x86_64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "15d12824fca2054bb2f1a0e72caa63744168fd9bfc028c588b0506e102dfb19d",
"md5": "d7a98148ff806ad0a18f22e1f3baf7db",
"sha256": "10b45c846057f4cd4c6b8410e4288148a9a7321620aea93eafcf2e0160877124"
},
"downloads": -1,
"filename": "linearmodels-6.0-cp39-cp39-macosx_11_0_arm64.whl",
"has_sig": false,
"md5_digest": "d7a98148ff806ad0a18f22e1f3baf7db",
"packagetype": "bdist_wheel",
"python_version": "cp39",
"requires_python": ">=3.9",
"size": 1493351,
"upload_time": "2024-04-16T17:43:09",
"upload_time_iso_8601": "2024-04-16T17:43:09.864579Z",
"url": "https://files.pythonhosted.org/packages/15/d1/2824fca2054bb2f1a0e72caa63744168fd9bfc028c588b0506e102dfb19d/linearmodels-6.0-cp39-cp39-macosx_11_0_arm64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "0e243aef212eb48b40cc8657c32a4d08d46d853c5845a2d84f72837160e2c3ab",
"md5": "60d425f88c4b83978be51d9cec25c672",
"sha256": "95e8d95cd84c6a51556f9c487ef88d293fcfed2baa648e721d34f7d89e5306ab"
},
"downloads": -1,
"filename": "linearmodels-6.0-cp39-cp39-win32.whl",
"has_sig": false,
"md5_digest": "60d425f88c4b83978be51d9cec25c672",
"packagetype": "bdist_wheel",
"python_version": "cp39",
"requires_python": ">=3.9",
"size": 1645749,
"upload_time": "2024-04-16T17:39:43",
"upload_time_iso_8601": "2024-04-16T17:39:43.980632Z",
"url": "https://files.pythonhosted.org/packages/0e/24/3aef212eb48b40cc8657c32a4d08d46d853c5845a2d84f72837160e2c3ab/linearmodels-6.0-cp39-cp39-win32.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-16 17:42:06",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "bashtage",
"github_project": "linearmodels",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"requirements": [],
"lcname": "linearmodels"
}