Skip to content
Ivan Svetunkov edited this page Oct 22, 2026 · 12 revisions

greybox Wiki

The greybox package is a toolbox for regression model building, selection and forecast evaluation. Its core is the Augmented Linear Model (ALM): a regression estimated by the likelihood of one of 25 distributions in R (26 in Python) or by another loss (8 named losses in R, 7 in Python, plus user-defined ones). Around it are stepwise selection, model combination, rolling-origin evaluation, error measures, measures of association, the identification of demand types, and data manipulation tools.

It is available for R (CRAN) and Python (PyPI). R is the original; the Python port has a scikit-learn-style interface and follows R's names, defaults and numbers.

Navigation aids

  • Glossary — overloaded terms (distribution values vs d*() functions, loss vs ic, the meanings of lags, R $ vs Python .).
  • Roadmap — what is R-only or not yet ported to Python.
  • R-Python-differences — numerical-parity status and interface differences.
  • Installation — installation instructions.
  • Resources — academic references and DOIs.
  • llms.txt — machine-readable index of every wiki page.

Quick Links

Functions

Models and selection

Page R Python Description
ALM alm() ALM Augmented Linear Model, with occurrence and scale parts and AR/I terms.
stepwise stepwise() stepwise() Forward selection of regressors.
CALM calm() CALM() Combination of ALMs weighted by information criteria.
distributions d/p/q/r*() d/p/q/r*() Distribution families of ALM.

Evaluation

Page R Python Description
measures measures(), MAE(), MASE(), … measures(), mae(), mase(), … Point, interval, quantile and half-moment error measures.
rolling_origin ro() rolling_origin() Rolling-origin evaluation.
RMCB rmcb() rmcb() Nemenyi / MCB comparison of forecasting methods.

Analysis and diagnostics

Page R Python Description
EDA stick() stick() Seasonality / trend / irregular decomposition of the variance.
association association(), pcor(), mcor(), cramer(), determination() the same names Measures of association.
diagnostics outlierdummy() outlier_dummy() Outlier detection and dummies.
AID aid(), aidCat() aid(), aid_cat() Automatic identification of demand.
Smoothers lowess(), supsmu() (stats) lowess(), supsmu() LOWESS and SuperSmoother.

Data manipulation

Page R Python Description
manipulations xregExpander(), xregTransformer(), xregMultiplier(), temporaldummy(), B(), multipliers() xreg_expander(), xreg_transformer(), xreg_multiplier(), temporal_dummy(), B(), multipliers() Lags and leads, transformations, cross-products, calendar dummies, distributed lags.

Python also ships R's mtcars dataset as a pandas DataFrame: from greybox import mtcars.

Getting Started

R

install.packages("greybox")
library(greybox)

model <- alm(mpg ~ wt + hp, mtcars[1:28,], distribution="dnorm")
summary(model)

best <- stepwise(mtcars, ic="AICc")     # mpg ~ wt + qsec + am

forecasts <- predict(model, mtcars[29:32,])$mean
round(measures(mtcars$mpg[29:32], forecasts, mtcars$mpg[1:28]), 4)
#     ME    MAE    MSE    MPE   MAPE    sCE   sMAE   sMSE   MASE  RMSSE   SAME
# 0.3483 1.6205 4.3384 0.0349 0.0960 0.0683 0.0795 0.0104 0.4207 0.3734 0.0904
#   rMAE  rRMSE   rAME asymmetry   sPIS
# 0.1304 0.1639 0.0280    0.0530 -0.2036

y <- cumsum(rnorm(100))
ro(y, h=5, origins=10, call="list(mean=rep(mean(data), h))", value="mean")

Python

pip install greybox
import numpy as np
from greybox import ALM, formula, stepwise, measures, rolling_origin, mtcars

y, X = formula("mpg ~ wt + hp", mtcars.head(28))
model = ALM(distribution="dnorm").fit(X, y)
print(model.summary())

best = stepwise(mtcars, ic="AICc")      # mpg ~ 1 + wt + qsec + am

_, X_new = formula("mpg ~ wt + hp", mtcars.tail(4))
forecasts = model.predict(X_new).mean
measures(mtcars["mpg"].tail(4).to_numpy(), forecasts, y)
# {'ME': 0.3483, 'MAE': 1.6205, 'MSE': 4.3384, 'MPE': 0.0349, 'MAPE': 0.096, ...}   (rounded)

series = np.cumsum(np.random.default_rng(42).normal(size=100))
rolling_origin(series, h=5, origins=10, call=lambda data, h: np.full(h, data.mean()))

R ↔ Python parity matrix

"Yes" means implemented with the same defaults and results (see R-Python-differences); "R only" items are on Roadmap.

Area R Python Status
Augmented Linear Model alm() ALM Yes; dchisq Python only, QUALE loss R only
Scale model sm(), implant() sm(), implant(), ALM(scale_formula=) Yes
Bootstrap of parameters coefbootstrap(), vcov(bootstrap=TRUE) coefbootstrap(), vcov(bootstrap=True) Yes
Distributed lags B(), multipliers() B(), multipliers() Yes
Stepwise selection stepwise() stepwise() Yes
Model combination calm() CALM() Partial (no formula, subset, parallel)
Dynamic combination lmDynamic() — R only
Prediction predict(), forecast() predict() Yes
Information criteria AIC(), AICc(), BIC(), BICc() aic, aicc, bic, bicc Yes
Point likelihood pointLik() point_lik(), point_lik_cumulative() Yes
Point information criteria pAIC(), pAICc(), pBIC() — R only
Residual diagnostics rstandard(), rstudent(), hatvalues(), cooks.distance() rstandard(), rstudent(), hatvalues() Partial (no Cook's distance)
Outlier dummies outlierdummy() outlier_dummy() Yes
Distributions d/p/q/r of the non-base families d/p/q/r of all families Yes, except dtplnorm (R only)
Error measures measures(), ME(), MAE(), …, MIS(), pinball(), hm(), … measures(), me(), mae(), …, mis(), pinball(), hm(), … Yes; rmse() Python only
Accuracy of a model accuracy() — R only
Rolling origin ro() rolling_origin() Yes
RMCB rmcb() rmcb() Yes
STI decomposition stick() stick() Yes
Association association(), pcor(), mcor(), cramer(), determination() the same Yes
Demand identification aid(), aidCat() aid(), aid_cat() Yes
Smoothers lowess(), supsmu() (stats) lowess(), supsmu() Yes
Regressor tools xregExpander(), xregTransformer(), xregMultiplier(), temporaldummy() xreg_expander(), xreg_transformer(), xreg_multiplier(), temporal_dummy() Yes
Plots graphmaker(), spread(), tableplot() graphmaker(), spread(), tableplot() Yes
Calendar and other utilities detectdst(), detectleap(), polyprod(), dsrboot() — R only

Naming conventions

R uses camelCase or lower-case names; Python uses snake_case functions and PascalCase classes.

R Python
alm() ALM().fit()
calm() CALM()
ro() rolling_origin()
aidCat() aid_cat()
pointLik() point_lik()
outlierdummy() outlier_dummy()
temporaldummy() temporal_dummy()
xregExpander(), xregTransformer(), xregMultiplier() xreg_expander(), xreg_transformer(), xreg_multiplier()
extractScale(), extractSigma() extract_scale(), extract_sigma()
ME(), MAE(), rMIS(), … me(), mae(), rmis(), …
x$name x.name

Clone this wiki locally