AI Decision System
Replayable, offline-verifiable records for AI-assisted go/no-go decisions: experiment promotions, typed model answers and human-approved actions.
statsmodels에 없는 도구변수와 패널 데이터 등 추가 선형 모델 제공
Additional linear models including instrumental variable and panel data models that are missing from statsmodels.
개발 도구Python · RGitHub @bashtage직접 설치운영자 미확인
써 보셨어요? 한 번만 눌러 주세요. 로그인은 필요 없어요.
메이커가 쓴 소개는 위의 한 줄이 전부입니다. 더 자세한 내용은 저장소 README에서 읽을 수 있습니다. 저장소 README ↗
README 전체를 불러오는 중입니다.
README 전문 보기 ↗| 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:
High-dimensional Regression:
Instrumental Variable estimators
Factor Asset Pricing Models:
System Regression:
Designed to work equally well with NumPy, Pandas or xarray data.
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.
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.
The latest release can be installed using pip
pip install linearmodels
Binary wheels are available for Windows, macOS and Linux. Without a wheel, pip builds linearmodels from source, which requires a C compiler.
The main branch can be installed by cloning the repo and building it with pip. The build uses meson-python, and pip installs the other build requirements (Cython, NumPy and setuptools_scm) automatically.
git clone https://github.com/bashtage/linearmodels
cd linearmodels
pip install .
To work on linearmodels, install the requirements and then build an editable install
python -m pip install -r requirements.txt -r requirements-dev.txt
python -m pip install -e . --no-build-isolation
The tests are installed with linearmodels. They need pytest 9 and xarray, and pytest-xdist to run in parallel.
python -c "import linearmodels; linearmodels.test(['--skip-slow', '-n', 'auto'])"
--skip-slow skips the slow tests and --skip-examples the example notebooks.
pytest loads every plugin that is installed in the environment, and the test
configuration of linearmodels is strict, so that, for example, a marker that is
not registered is an error. A plugin that uses such a marker makes tests fail
with a message such as 'gpu' not found in markers configuration option. To run
the tests without the other plugins, turn off their automatic loading and load
pytest-xdist explicitly. This works with python -m pytest too.
PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 python -c "import linearmodels; linearmodels.test(['-p', 'xdist', '-n', 'auto'])"
When the tests run in several processes with pytest-xdist, limit the BLAS libraries to one thread in each process. Otherwise every process starts as many threads as there are cores, and excessive context switching makes the tests run very slow. This problem is particularly acute on machines with high CPU counts.
export MKL_NUM_THREADS=1
export OPENBLAS_NUM_THREADS=1
export OMP_NUM_THREADS=1
or, in PowerShell,
$env:MKL_NUM_THREADS = 1
$env:OPENBLAS_NUM_THREADS = 1
$env:OMP_NUM_THREADS = 1
Stable Documentation is built by GitHub Actions when a release is published. Development Documentation is built by the same workflow on every push to main.
linearmodels 7.1 is the last release that supports Python 3.10 and NumPy 1.x (NumPy < 2). Later releases will raise the minimum supported versions of Python, NumPy and the other dependencies.