Skip to main content

Truncated Gaussian Regression Models

Project description

pytruncreg Overview

PyPI version Downloads
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 to True the 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 algorithm
  • SE an array containing the standard errors for intercept and coefficients
  • vcov the 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

pytruncreg-1.0.1.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytruncreg-1.0.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

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

Hashes for pytruncreg-1.0.1.tar.gz
Algorithm Hash digest
SHA256 6af3e07c5f43da8c6151787da5947efab5cea8d4079973ff40f0a25f0dac17cd
MD5 ee5c30cdfeefeaa9c1ace03497968a91
BLAKE2b-256 45801418c3031cc7e6443712820f17067467bc932e15c5225544873190ed2539

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytruncreg-1.0.1.tar.gz:

Publisher: publish.yml on CausalInference/pytruncreg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for pytruncreg-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f48ae68e113e81e19b7a6e7cda78b1c9559918acd52412d6563b38fd4cb6a0cb
MD5 c05101db10d83457eb02e710c742c4ea
BLAKE2b-256 881a519f4b27897e2cccac25298b3126fda05f9bfed6b81f0e1be81324729c15

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytruncreg-1.0.1-py3-none-any.whl:

Publisher: publish.yml on CausalInference/pytruncreg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page