--- id: formulaic-contrasts version: "1.0.0" 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) license_treatment: permissive maintenance: active --- # formulaic-contrasts — Build contrasts for models defined with formulaic License: permissive · Maintenance: active · Downloads: 159.6K/mo ## 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 above — 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 pip install formulaic-contrasts uv add formulaic-contrasts 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_current - Install friction: low - Maintenance: active - Downloads: 159.6K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags contrast coding for models, formulaic contrasts, categorical variable comparisons, model contrast matrices, statistical contrast building, formula-based contrasts, custom contrast schemes, statistical-modeling, contrasts, formula-system [View on SkillFed](https://skillfed.io/packages/formulaic-contrasts) · [View on PyPI](https://pypi.org/project/formulaic-contrasts/)