The peticontrast package provides a simple way to apply sum coding (effect coding) to factors in OLS models.
In R, the default is Treatment Coding (contr.treatment), where each level is compared to a reference category (baseline). The intercept represents the mean of that baseline category.
Sum Coding (implemented here as apply_peticontrast) compares each level to the grand mean (trend) of all categories. In this case:
This is particularly useful for seasonal data where you want to see how each period (e.g., Quarter) differs from the yearly trend.
# Internal use only
library(peticontrast)
df <- data.frame(Month = factor(c("Jan", "Feb", "Mar", "Apr")))
df <- apply_peticontrast(df, "Month")
summary(lm(Value ~ Month, data = df))