Truncated Gaussian Regression Models
Project description
pytruncreg Overview
The pytruncreg package developed by Harvard University's CausaLab is designed to estimate one-way truncated gaussian regression models. The truncreg function requires formula, data, a truncation point and direction of truncation. This python package is a translation of the original truncreg R package CRAN by Yves Croissant and Achim Zeileis.
Parameters
- formula (str): String describing the model to be fitted in format
y ~ x_1 + x_2 + ... x_n - data (DataFrame): The dataset containing the variables specified in the formula
- point (float): The point of truncation in
y - direction (str): Specifies the direction of truncation, taking values
"left"or"right" - scaled (bool, optional): Default is
False. When set toTruethe model will use a scaled version of the dependent variable - iterlim (int, optional): Default is 50. The maximum iterations for the optimization algorithm.
Returns
OptimizeResult: an object containing the results of the results of the optimization algorithmSEan array containing the standard errors for intercept and coefficientsvcovthe hessian (variance-covariance matrix) from the optimization process
Description
The truncreg function based on the original truncreg R package CRAN by Yves Croissant and Achim Zeileis, performs maximum likelihood estimation of a truncated gaussian regression model. The function supports both left and right truncation and will extract variables inside of formula from the provided data then constructs the model matrix by supplying an intercept and fits the truncated regression model using the L-BFGS-B optimization algorithm. Internally, the function calculates the log-likelihood, gradient, and Hessian matrix for the optimization process. The initial values for beta coefficients are estimated using ordinary least squares.\
In the case of overflow, truncreg will attempt to handle potential overflow issues in calculating the Mills ratio and log-likelihood. If scaled=True, the dependent variable is scaled before estimation.
Example Usage
import pandas as pd
import numpy as np
from pytruncreg import truncreg
np.random.seed(42)
data = pd.DataFrame({
'y': np.random.normal(0, 1, 1000),
'x1': np.random.normal(1, 3, 1000),
'x2': np.random.normal(10, 3, 1000)
})
result = truncreg(formula='y~x1+x2', data=data, point=-4, direction='left')
print(result)
Dependencies
- numpy
- scipy.stats
- scipy.optimize
- re
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytruncreg-1.0.1.tar.gz.
File metadata
- Download URL: pytruncreg-1.0.1.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6af3e07c5f43da8c6151787da5947efab5cea8d4079973ff40f0a25f0dac17cd
|
|
| MD5 |
ee5c30cdfeefeaa9c1ace03497968a91
|
|
| BLAKE2b-256 |
45801418c3031cc7e6443712820f17067467bc932e15c5225544873190ed2539
|
Provenance
The following attestation bundles were made for pytruncreg-1.0.1.tar.gz:
Publisher:
publish.yml on CausalInference/pytruncreg
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytruncreg-1.0.1.tar.gz -
Subject digest:
6af3e07c5f43da8c6151787da5947efab5cea8d4079973ff40f0a25f0dac17cd - Sigstore transparency entry: 680595031
- Sigstore integration time:
-
Permalink:
CausalInference/pytruncreg@a625556349c309f36ac576e80eaf42fa65bf6276 -
Branch / Tag:
refs/tags/1.0.1 - Owner: https://github.com/CausalInference
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a625556349c309f36ac576e80eaf42fa65bf6276 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pytruncreg-1.0.1-py3-none-any.whl.
File metadata
- Download URL: pytruncreg-1.0.1-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f48ae68e113e81e19b7a6e7cda78b1c9559918acd52412d6563b38fd4cb6a0cb
|
|
| MD5 |
c05101db10d83457eb02e710c742c4ea
|
|
| BLAKE2b-256 |
881a519f4b27897e2cccac25298b3126fda05f9bfed6b81f0e1be81324729c15
|
Provenance
The following attestation bundles were made for pytruncreg-1.0.1-py3-none-any.whl:
Publisher:
publish.yml on CausalInference/pytruncreg
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytruncreg-1.0.1-py3-none-any.whl -
Subject digest:
f48ae68e113e81e19b7a6e7cda78b1c9559918acd52412d6563b38fd4cb6a0cb - Sigstore transparency entry: 680595044
- Sigstore integration time:
-
Permalink:
CausalInference/pytruncreg@a625556349c309f36ac576e80eaf42fa65bf6276 -
Branch / Tag:
refs/tags/1.0.1 - Owner: https://github.com/CausalInference
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a625556349c309f36ac576e80eaf42fa65bf6276 -
Trigger Event:
release
-
Statement type: