Skip to main content

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

Metadata

Release files for pytruncreg 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytruncreg 1.0.1
File Size Uploaded
pytruncreg-1.0.1.tar.gz 4.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytruncreg 1.0.1
File Interpreter ABI Platform
pytruncreg-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 9.8 kB

Release files / pytruncreg-1.0.1.tar.gz

Download URL pytruncreg-1.0.1.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
6af3e07c5f43da8c6151787da5947efab5cea8d4079973ff40f0a25f0dac17cd
BLAKE2b-256 checksum
How to use checksums
45801418c3031cc7e6443712820f17067467bc932e15c5225544873190ed2539
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 7, 2025.

Transparency log

Release files / pytruncreg-1.0.1-py3-none-any.whl

Download URL pytruncreg-1.0.1-py3-none-any.whl
Size 5.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f48ae68e113e81e19b7a6e7cda78b1c9559918acd52412d6563b38fd4cb6a0cb
BLAKE2b-256 checksum
How to use checksums
881a519f4b27897e2cccac25298b3126fda05f9bfed6b81f0e1be81324729c15
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 7, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page