skillfed

formulaic-contrasts

Build contrasts for models defined with formulaic

formulaic-contrasts v1.0.0 159.6K downloads/30d#10,692 on PyPI13
Permissive license BSD 3-Clause License Copyright (c) 2024, Gregor Sturm All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following… (full text in the JSON record) Active released

What it is and what it does

formulaic-contrasts extends the formulaic formula system with tools to build custom contrast matrices for categorical variables in statistical models. It provides functions like cond() to specify arbitrary comparison schemes, enabling researchers to define exactly how categorical predictors are encoded when fitting models. The package is designed for use within the scverse ecosystem and statistical modeling workflows where fine-grained control over contrast coding is needed.

The package depends on formulaic for formula parsing, pandas for data handling, and session-info for environment tracking. It targets Python 3.10+ and is actively maintained. Installation is straightforward via pip, and the library is intended to be used both directly by developers building custom models and indirectly as a dependency of higher-level statistical packages.

Use it for:

  • Specify custom contrast schemes (e.g., treatment, sum, Helmert) for categorical variables in regression or generalized linear models.
  • Build multi-condition comparisons in biological or scientific models where standard contrast coding is insufficient.
  • Integrate contrast specification into formulaic-based model definitions for reproducible statistical workflows.
  • Develop custom statistical modeling libraries that need flexible contrast matrix generation.
  • Encode categorical predictors with domain-specific comparison logic in machine learning pipelines.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Builds arbitrary contrasts for statistical models defined using the formulaic formula system, enabling flexible comparison coding for categorical variables in model specifications.

Yes, if you use formulaic-based models and need custom contrast coding. The package is actively maintained, has no known vulnerabilities, low install friction, and a permissive license. It is niche—primarily useful for statistical modeling and research workflows—but well-suited to that purpose. Not necessary for general-purpose Python development.

Install

formulaic-contrasts on PyPI

pip

pip install formulaic-contrasts

uv

uv add formulaic-contrasts

poetry

poetry add formulaic-contrasts

Installing formulaic-contrasts

Before you install

Low friction installation with a pure-Python wheel. Active maintenance as of August 2026 with recent commits. Requires Python 3.10 or later. Three runtime dependencies (formulaic, pandas, session-info) are standard data-science libraries.

License in practice

BSD 3-Clause permissive license allows commercial use, modification, and distribution with minimal restrictions—attribution and liability disclaimer required.

Quickstart

pip install formulaic-contrasts

from formulaic_contrasts import ...
import formulaic
import pandas

# Build contrasts for a model formula
# See documentation for specific contrast functions

Requires Python 3.10 or later.

Verify before relying

  • What specific contrast types or schemes the package supports beyond the cond() function mentioned in credits.
  • Whether the package is typically used standalone or primarily as a dependency of other statistical modeling libraries.
  • Performance characteristics when working with large categorical datasets or many contrast levels.

Package facts

License BSD 3-Clause License Copyright (c) 2024, Gregor Sturm All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following… (full text in the JSON record) (permissive)
Python support supports the current Python release (>=3.10)
Install friction low — pure-Python wheel
Runtime dependencies 3 — formulaic, pandas, session-info
Maintenance actively maintained — 607 days since the last release
Last repo commit
First released
Downloads 159,637/month — #10,692 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: formulaic_contrasts-1.0.0-py3-none-any.whl

Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13

Tags

contrast coding for modelsformulaic contrastscategorical variable comparisonsmodel contrast matricesstatistical contrast buildingformula-based contrastscustom contrast schemes
statistical-modelingcontrastsformula-system

More Scientific/Engineering packages