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

python -m pip install kernelmix

For plots, use python -m pip install "kernelmix[plots]".

Or install the released source directly from GitHub:

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

Python 3.10 or later is required.

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.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 kernelmix 0.3.1
File Size Uploaded Provenance
kernelmix-0.3.1.tar.gz 2.4 MB With provenance Details

Built distribution (wheel)

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

Total release size: 2.5 MB

Release files / kernelmix-0.3.1.tar.gz

Download URL kernelmix-0.3.1.tar.gz
Size 2.4 MB
Tags Source
SHA-256 checksum
How to use checksums
4f72de42d903bedf6b98ffedeb1aee99d471e2cf979ff30fc1ec78ae59624ab2
BLAKE2b-256 checksum
How to use checksums
684f59e4b6277a47b7df1417dd1b5228fd68883aa6ea689f4c05c60ebefd5e6b
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.1-py3-none-any.whl

Download URL kernelmix-0.3.1-py3-none-any.whl
Size 92.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
66de3cf3194d6dbb68b275f9a90a91ed47e7246c2ff8702dd48619c0058fa499
BLAKE2b-256 checksum
How to use checksums
f7645dc26927ea7c3d4b443e644c133af5a7d7f71c1d0274a511f747c2e331e8
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.1

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.1.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.1 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