Title: Professional Contrast Coding for OLS Models
Version: 0.1.0
Description: Automates sum coding (also known as effect coding) for Ordinary Least Squares (OLS) regression models. This approach is specifically designed to handle seasonal time series and categorical variables by comparing each group to the grand mean, rather than a single baseline category. This ensures that the intercept represents the unweighted grand mean of the dependent variable. For a comprehensive overview of contrast coding systems, see the UCLA Advanced Research Computing documentation (2021) https://stats.oarc.ucla.edu/r/library/r-library-contrast-coding-systems-for-categorical-variables/.
License: MIT + file LICENSE
Encoding: UTF-8
RoxygenNote: 7.2.3
Imports: stats
Suggests: knitr
Config/testthat/edition: 3
NeedsCompilation: no
Packaged: 2026-04-22 10:51:15 UTC; petya
Author: Peti Mester [aut, cre]
Maintainer: Peti Mester <petyatoth2005@gmail.com>
Repository: CRAN
Date/Publication: 2026-04-23 19:40:02 UTC

Apply PetiContrast (Sum Coding) to a Data Frame

Description

This function applies a custom sum coding (effect coding) to a specified factor column in a data frame. It is designed for OLS models where you want to compare each level to the overall trend (mean) rather than a baseline category.

Usage

apply_peticontrast(data, col_name)

Arguments

data

A data.frame.

col_name

A string specifying the column name to transform.

Value

A data.frame with the modified contrasts for the specified column.

Examples

df <- data.frame(Quarter = factor(c("Q1", "Q2", "Q3", "Q4", "Q1", "Q2")))
df_new <- apply_peticontrast(df, "Quarter")
contrasts(df_new$Quarter)