| Title: | Clock of Regimes Naive Bayes Classifier (Student-t) |
|---|---|
| Description: | Computes and fits a heavy-tailed Student-t Naive Bayes classifier for non-stationary financial market regime analysis (Clock of Regimes, COR). The core innovation is a profile grid search over the degrees-of-freedom parameter nu that prevents numerical underflow and structural classification failures when identifying fat-tailed Stress regimes. Provides S3 methods for fitting, prediction, summarising, plotting, and parameter extraction. |
| Authors: | Oscar Linares [aut, cre] |
| Maintainer: | Oscar Linares <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.1 |
| Built: | 2026-05-31 10:04:53 UTC |
| Source: | https://github.com/cran/kronxNBC |
Returns a data frame of fitted Student-t parameters (, ,
) organised by feature (rows) and class (column groups).
## S3 method for class 'student_t_naive_bayes' coef(object, ...)## S3 method for class 'student_t_naive_bayes' coef(object, ...)
object |
A fitted |
... |
Additional arguments (currently unused). |
A data frame with rows (features) and columns,
named <class>:mu, <class>:sd, <class>:nu for each of
the classes.
set.seed(7) X <- matrix(rnorm(120), 60, 2, dimnames = list(NULL, c("f1", "f2"))) y <- factor(rep(c("A", "B", "C"), 20)) m <- student_t_naive_bayes(X, y) coef(m)set.seed(7) X <- matrix(rnorm(120), 60, 2, dimnames = list(NULL, c("f1", "f2"))) y <- factor(rep(c("A", "B", "C"), 20)) m <- student_t_naive_bayes(X, y) coef(m)
Draws per-feature Student-t density curves, one curve per class, for
a fitted "student_t_naive_bayes" model.
## S3 method for class 'student_t_naive_bayes' plot( x, which = NULL, ask = FALSE, legend = TRUE, legend.box = FALSE, arg.num = list(), prob = c("marginal", "conditional"), ... )## S3 method for class 'student_t_naive_bayes' plot( x, which = NULL, ask = FALSE, legend = TRUE, legend.box = FALSE, arg.num = list(), prob = c("marginal", "conditional"), ... )
x |
A fitted |
which |
Integer or character vector selecting which features to plot.
|
ask |
Logical. If |
legend |
Logical. If |
legend.box |
Logical. If |
arg.num |
Named list of graphical parameters (e.g. |
prob |
Character string: |
... |
Additional graphical arguments passed to |
Invisibly returns NULL.
Computes MAP class assignments or posterior probabilities for new
observations using a fitted student_t_naive_bayes model.
## S3 method for class 'student_t_naive_bayes' predict( object, newdata = NULL, type = c("class", "prob"), threshold = 0.001, eps = 0, ... )## S3 method for class 'student_t_naive_bayes' predict( object, newdata = NULL, type = c("class", "prob"), threshold = 0.001, eps = 0, ... )
object |
A fitted |
newdata |
Optional numeric matrix of new observations with the same
named columns as the training matrix. If |
type |
Character string: |
threshold |
Minimum log-density floor applied after the |
eps |
Densities at or below this value are replaced by
|
... |
Additional arguments (currently unused). |
type = "class"A factor of length
nrow(newdata) with levels matching the training classes.
type = "prob"A numeric matrix with nrow(newdata)
rows and one column per class, containing softmax-normalised posterior
probabilities.
set.seed(1) X <- matrix(rnorm(100), 50, 2, dimnames = list(NULL, c("f1", "f2"))) y <- factor(rep(c("A", "B"), 25)) m <- student_t_naive_bayes(X, y) predict(m, type = "class") predict(m, type = "prob")set.seed(1) X <- matrix(rnorm(100), 50, 2, dimnames = list(NULL, c("f1", "f2"))) y <- factor(rep(c("A", "B"), 25)) m <- student_t_naive_bayes(X, y) predict(m, type = "class") predict(m, type = "prob")
Prints a concise summary of the model, including the call, prior probabilities, and the first five parameter tables.
## S3 method for class 'student_t_naive_bayes' print(x, ...)## S3 method for class 'student_t_naive_bayes' print(x, ...)
x |
A fitted |
... |
Additional arguments (currently unused). |
Invisibly returns x.
student_t_naive_bayes,
summary.student_t_naive_bayes
Fits a Naive Bayes classifier where the per-class, per-feature likelihood is
a scaled Student-t distribution. The degrees-of-freedom parameter
is selected for every (class, feature) pair by a profile log-likelihood grid
search over nu_grid, making the model robust to the fat-tailed returns
that characterise financial Stress regimes.
student_t_naive_bayes(x, y, prior = NULL, nu_grid = c(3:30, 40, 60, 100), ...)student_t_naive_bayes(x, y, prior = NULL, nu_grid = c(3:30, 40, 60, 100), ...)
x |
A numeric matrix of predictors with named columns. Each column is one feature; each row is one observation. |
y |
A factor, character, or logical vector of class labels with length
equal to |
prior |
Optional named numeric vector of prior class probabilities. Length must equal the number of class levels. Defaults to empirical class frequencies. Supplied values are normalised to sum to one. |
nu_grid |
Numeric vector of candidate degrees-of-freedom values used by
the profile grid search. All values must be strictly greater than 2
(finite-variance requirement). Default:
|
... |
Additional arguments (currently unused). |
**Classification rule (MAP)**
Under the Naive Bayes conditional-independence assumption the posterior log-odds reduce to the Maximum A Posteriori rule:
where the scaled Student-t density is
and is the prior probability of class .
**Degrees-of-freedom grid search**
For each (class , feature ) pair the algorithm runs one IRLS
step at every candidate nu_grid and retains the triplet
that maximises the profile
log-likelihood. This discrete search avoids the numerical instability of
continuous optimisation and is the mechanism that prevents
log-likelihood underflow when scoring crisis observations in the Stress
regime.
An S3 object of class "student_t_naive_bayes" with components:
dataList with elements x (training matrix) and
y (training labels).
levelsCharacter vector of class levels.
paramsNamed list with matrices
mu, sd, and nu ( = classes,
= features).
priorNamed numeric vector of prior probabilities.
nu_gridThe nu_grid vector used during fitting.
callThe matched call.
predict.student_t_naive_bayes,
tables.student_t_naive_bayes,
coef.student_t_naive_bayes
set.seed(42) n <- 150 y <- factor(rep(c("Calm", "Stress", "Trend"), each = n / 3)) X <- matrix( c(rnorm(50, 0, 1), rt(50, df = 4), rnorm(50, 1, 0.5), rnorm(50, 0, 1), rt(50, df = 4), rnorm(50, 1, 0.5)), nrow = n, ncol = 2, dimnames = list(NULL, c("ret", "vol")) ) model <- student_t_naive_bayes(X, y) print(model)set.seed(42) n <- 150 y <- factor(rep(c("Calm", "Stress", "Trend"), each = n / 3)) X <- matrix( c(rnorm(50, 0, 1), rt(50, df = 4), rnorm(50, 1, 0.5), rnorm(50, 0, 1), rt(50, df = 4), rnorm(50, 1, 0.5)), nrow = n, ncol = 2, dimnames = list(NULL, c("ret", "vol")) ) model <- student_t_naive_bayes(X, y) print(model)
Prints a high-level summary of a fitted "student_t_naive_bayes"
model: sample size, feature count, grid range, and prior
probabilities.
## S3 method for class 'student_t_naive_bayes' summary(object, ...)## S3 method for class 'student_t_naive_bayes' summary(object, ...)
object |
A fitted |
... |
Additional arguments (currently unused). |
Invisibly returns object.
student_t_naive_bayes,
print.student_t_naive_bayes
S3 generic that returns per-feature parameter tables for a fitted Naive
Bayes model. For "student_t_naive_bayes" objects each table contains
the fitted , , and parameters. For all
other model classes the call is forwarded to naivebayes::tables().
tables(object, which = NULL, ...) ## S3 method for class 'student_t_naive_bayes' tables(object, which = NULL, ...) ## Default S3 method: tables(object, which = NULL, ...)tables(object, which = NULL, ...) ## S3 method for class 'student_t_naive_bayes' tables(object, which = NULL, ...) ## Default S3 method: tables(object, which = NULL, ...)
object |
A fitted Naive Bayes model. Supported classes:
|
which |
Integer or character vector selecting which feature tables to
return. |
... |
Additional arguments passed to the method. |
A "naive_bayes_tables" object: a named list with one element
per selected feature. For "student_t_naive_bayes" objects each
element is a table with rows mu, sd,
nu and one column per class level.
set.seed(3) X <- matrix(rnorm(120), 60, 2, dimnames = list(NULL, c("ret", "vol"))) y <- factor(rep(c("Calm", "Stress", "Trend"), 20)) m <- student_t_naive_bayes(X, y) tables(m) tables(m, which = "ret") tables(m, which = 2L)set.seed(3) X <- matrix(rnorm(120), 60, 2, dimnames = list(NULL, c("ret", "vol"))) y <- factor(rep(c("Calm", "Stress", "Trend"), 20)) m <- student_t_naive_bayes(X, y) tables(m) tables(m, which = "ret") tables(m, which = 2L)