| Type: | Package |
| Title: | Clock of Regimes Naive Bayes Classifier (Student-t) |
| Version: | 0.1.1 |
| 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. |
| License: | MIT + file LICENSE |
| Encoding: | UTF-8 |
| Imports: | stats, graphics, utils, naivebayes |
| Suggests: | zoo, testthat (≥ 3.0.0), knitr, rmarkdown |
| VignetteBuilder: | knitr |
| Config/testthat/edition: | 3 |
| Config/roxygen2/version: | 8.0.0 |
| NeedsCompilation: | no |
| Packaged: | 2026-05-27 19:22:36 UTC; olinaresmd |
| Author: | Oscar Linares [aut, cre] |
| Maintainer: | Oscar Linares <olinares@umich.edu> |
| Repository: | CRAN |
| Date/Publication: | 2026-05-30 13:50:02 UTC |
kronxNBC: 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.
Author(s)
Maintainer: Oscar Linares olinares@umich.edu
Authors:
Oscar Linares olinares@umich.edu
Coefficient extraction for student_t_naive_bayes
Description
Returns a data frame of fitted Student-t parameters (\mu, \sigma,
\nu) organised by feature (rows) and class (column groups).
Usage
## S3 method for class 'student_t_naive_bayes'
coef(object, ...)
Arguments
object |
A fitted |
... |
Additional arguments (currently unused). |
Value
A data frame with p rows (features) and 3K columns,
named <class>:mu, <class>:sd, <class>:nu for each of
the K classes.
See Also
Examples
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)
Plot method for student_t_naive_bayes
Description
Draws per-feature Student-t density curves, one curve per class, for
a fitted "student_t_naive_bayes" model.
Usage
## 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"),
...
)
Arguments
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 |
Value
Invisibly returns NULL.
See Also
Predict method for student_t_naive_bayes
Description
Computes MAP class assignments or posterior probabilities for new
observations using a fitted student_t_naive_bayes model.
Usage
## S3 method for class 'student_t_naive_bayes'
predict(
object,
newdata = NULL,
type = c("class", "prob"),
threshold = 0.001,
eps = 0,
...
)
Arguments
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). |
Value
type = "class"A
factorof lengthnrow(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.
See Also
Examples
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")
Print method for student_t_naive_bayes
Description
Prints a concise summary of the model, including the call, prior probabilities, and the first five parameter tables.
Usage
## S3 method for class 'student_t_naive_bayes'
print(x, ...)
Arguments
x |
A fitted |
... |
Additional arguments (currently unused). |
Value
Invisibly returns x.
See Also
student_t_naive_bayes,
summary.student_t_naive_bayes
Student-t Naive Bayes Classifier
Description
Fits a Naive Bayes classifier where the per-class, per-feature likelihood is
a scaled Student-t distribution. The degrees-of-freedom parameter \nu
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.
Usage
student_t_naive_bayes(x, y, prior = NULL, nu_grid = c(3:30, 40, 60, 100), ...)
Arguments
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). |
Details
**Classification rule (MAP)**
Under the Naive Bayes conditional-independence assumption the posterior log-odds reduce to the Maximum A Posteriori rule:
\hat{k} = \arg\max_{k \in \{1,\dots,K\}} \Bigl[
\log \pi_k +
\sum_{j=1}^{p}
\log f_{t}\!\left(x_j \,\Big|\, \mu_{kj},\, \sigma_{kj},\, \nu_{kj}\right)
\Bigr]
where the scaled Student-t density is
f_{t}(x \mid \mu, \sigma, \nu) =
\frac{1}{\sigma}\,
f_{t_\nu}\!\!\left(\frac{x - \mu}{\sigma}\right)
and \pi_k is the prior probability of class k.
**Degrees-of-freedom grid search**
For each (class k, feature j) pair the algorithm runs one IRLS
step at every candidate \nu \in nu_grid and retains the triplet
(\hat\mu, \hat\sigma, \hat\nu) that maximises the profile
log-likelihood. This discrete search avoids the numerical instability of
continuous \nu optimisation and is the mechanism that prevents
log-likelihood underflow when scoring crisis observations in the Stress
regime.
Value
An S3 object of class "student_t_naive_bayes" with components:
dataList with elements
x(training matrix) andy(training labels).levelsCharacter vector of class levels.
paramsNamed list with
K \times pmatricesmu,sd, andnu(K= classes,p= features).priorNamed numeric vector of prior probabilities.
nu_gridThe
nu_gridvector used during fitting.callThe matched call.
See Also
predict.student_t_naive_bayes,
tables.student_t_naive_bayes,
coef.student_t_naive_bayes
Examples
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)
Summary method for student_t_naive_bayes
Description
Prints a high-level summary of a fitted "student_t_naive_bayes"
model: sample size, feature count, \nu grid range, and prior
probabilities.
Usage
## S3 method for class 'student_t_naive_bayes'
summary(object, ...)
Arguments
object |
A fitted |
... |
Additional arguments (currently unused). |
Value
Invisibly returns object.
See Also
student_t_naive_bayes,
print.student_t_naive_bayes
Parameter tables for Naive Bayes classifiers
Description
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 \mu, \sigma, and \nu parameters. For all
other model classes the call is forwarded to naivebayes::tables().
Usage
tables(object, which = NULL, ...)
## S3 method for class 'student_t_naive_bayes'
tables(object, which = NULL, ...)
## Default S3 method:
tables(object, which = NULL, ...)
Arguments
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. |
Value
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.
See Also
Examples
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)