Skip to main content

KernelMix

KernelMix fits Bayesian kernel machine regression (BKMR) for exposure mixtures in Python. It models how an outcome varies with several exposures together, allowing curved associations and interactions between exposures. Other measured variables enter as linear adjustment terms.

To handle different outcome types, the package combines this exposure function with continuous, binary, count or survival models. NumPy and SciPy handle fitting and prediction; R is not required.

Task Start here
Choose an outcome model and priors Models and assumptions
Fit, inspect, predict and compare exposures Analysis tutorial
Model clusters, kernels or detailed survival records Structured models
Find arguments and result fields API reference
Check numerical evidence and limitations Evidence

Install

Install directly from GitHub:

python -m pip install "kernelmix[plots] @ git+https://github.com/nilson01/kernelmix.git@main"

Or, from a downloaded source folder:

python -m pip install ".[plots]"

Python 3.10 or later is required. Omit [plots] if plots are not needed.

Example

import numpy as np
from kernelmix import fit, univariate_response, plot_response

rng = np.random.default_rng(17)
Z = rng.normal(size=(24, 2))
y = np.sin(Z[:, 0]) + 0.3 * Z[:, 1] + rng.normal(0, 0.5, 24)
result = fit(y, Z, draws=200, warmup=200, chains=2, seed=17)
print(result.summary())
curve = univariate_response(result, variable=0, points=25, seed=17)
ax = plot_response(curve)

Example output (first rows):

BKMRFit(family='gaussian', n=24, exposures=2, chains=2, draws=200)
95% pointwise credible intervals
Parameter             Mean         SD      Lower      Upper
lambda               16.93      9.047      4.145      38.61
sigma2              0.2159    0.08346     0.1142     0.4188

These short chains illustrate the output and trigger mixing warnings. For an analysis, use longer runs and inspect agreement between chains and effective sample sizes, which account for dependence between draws.

Exposure response curve with pointwise 95% credible intervals

The curve varies the first exposure with the second at its median, relative to the all-median exposure profile. It describes a fitted association; a causal interpretation requires additional assumptions.

Documentation

Browse the searchable documentation.

The common questions explain prediction scales, missing values, selection and diagnostics. The observed ozone example includes source data and saved results. Download the reference manual for offline reading. Contributors can find development checks separately.

References and license

Bobb et al. (2015) introduced BKMR for exposure-mixture analysis. Bobb et al. (2018) described the R software and its binary-outcome extension. KernelMix implements these methods separately in Python and adds count and survival likelihoods, defined in the model guide.

We compare selected Gaussian and probit posterior summaries and conditional calculations, including random intercepts, with installed R bkmr 0.2.2. The evidence summary records results and limits. See NOTICE for attribution and LICENSE for GPL-2.0-only terms.

Metadata

Release files for kernelmix 0.3.0

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

Source distribution (sdist)

Source distribution for kernelmix 0.3.0
File Size Uploaded Provenance
kernelmix-0.3.0.tar.gz 2.4 MB With provenance Details

Built distribution (wheel)

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

Total release size: 2.5 MB

Release files / kernelmix-0.3.0.tar.gz

Download URL kernelmix-0.3.0.tar.gz
Size 2.4 MB
Tags Source
SHA-256 checksum
How to use checksums
7b9f2821168ec23c5afab8bd59d201dc848519ff8266fda3d8d6ed114afb716f
BLAKE2b-256 checksum
How to use checksums
f753fb28784942aad5485291028d1aaf784d64405b4fe0a5bd5d0eb2f12d8847
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Oct 26, 2026.

Transparency log

Release files / kernelmix-0.3.0-py3-none-any.whl

Download URL kernelmix-0.3.0-py3-none-any.whl
Size 92.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
633817bb7bb64eff54cf927a963775e343a97ef76777396681677455fc83a848
BLAKE2b-256 checksum
How to use checksums
ff22243f679c33482c5a7cbeb9539eab737e78b8975ce672154f1ccf5a82ef59
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Oct 26, 2026.

Transparency log

Security for kernelmix 0.3.0

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for kernelmix-0.3.0.tar.gz

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 Oct 26, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files Full provenance

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