Skip to main content

A package for fitting an interval and mixed effect interval regression model to censored and/or uncensored point and/or interval data

Project description

codecov DOI

intreg

intreg is a lightweight Python package for fitting interval regression models to censored and interval-bounded data using maximum likelihood estimation.

It provides:

  • Interval regression (IntReg) for left-, right-, exact-, and interval-censored data
  • Mixed-effects interval regression (MeIntReg) using random intercepts
  • Optional L2 regularisation for fixed and random effects
  • A clean NumPy/SciPy-based API suitable for modelling, research, and simulation

The package is useful for modelling censored continuous outcomes such as MIC values, detection limits, truncated biological measurements, and any interval-coded response.


📦 Installation

Install from PyPI

pip install intreg

Install from source (developer mode)

pip install -e .

🧩 Package Structure

The package exposes two core classes:

Class Description
IntReg Interval regression without random effects. Handles all types of censoring.
MeIntReg Mixed-effects interval regression with random intercepts

Both models:

  • use a Gaussian likelihood
  • parameterise variance via log(sigma) for stability
  • accept optional L2_penalties={} to regularise parameters
  • optimise using scipy.optimize.minimize

Project layout (under src/):

intreg/
    __init__.py
    intreg.py
    meintreg.py

🔧 Basic Usage

1. Interval Regression (IntReg)

import numpy as np
from intreg import IntReg

y_lower = np.array([1.0, 2.0, -np.inf, 3.0])
y_upper = np.array([1.0, 2.5, 1.5, np.inf])

model = IntReg(y_lower, y_upper)
model.fit()

print(model.result.x)  # estimated [mu, log_sigma]

2. Mixed-Effects Interval Regression (MeIntReg)

import numpy as np
from intreg import MeIntReg

y_low = np.array([1.0, 2.0, 1.5, -np.inf])
y_high = np.array([1.0, 2.2, np.inf, 1.0])

X = np.column_stack([np.ones(4)])  # intercept-only model
groups = np.array([0, 0, 1, 1])

model = MeIntReg(y_low, y_high, X, random_effects=groups)
model.fit()

print(model.result.x)  # [beta, random_effects, log_sigma]

🧪 Testing

Tests are stored under:

temp/tests/

Run them using:

pytest

📄 License

MIT License.

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

intreg-0.2.2.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

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

intreg-0.2.2-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file intreg-0.2.2.tar.gz.

File metadata

  • Download URL: intreg-0.2.2.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for intreg-0.2.2.tar.gz
Algorithm Hash digest
SHA256 d12805d9f68f1ad92289915e7a9a3919a51a81c0d853737e327a01053bf6bda7
MD5 65f10e3c01cd3e732bab83b6d4882f4c
BLAKE2b-256 154b22bd3c067e69f4ad44cefe3e87b0c840927d0376ae77c14db800c8f4639e

See more details on using hashes here.

File details

Details for the file intreg-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: intreg-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for intreg-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bf64d653987a26fda5ca23e65c80ce6caaa1824e4780096a4194c003dd8cd60c
MD5 011bc624d635a6cb55bc1ce7cca5bd23
BLAKE2b-256 26c1ab2edd6bedb3b0c29232b6cd697e8c92deb7f5f9dec34544898e78e949bc

See more details on using hashes here.

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