| Title: | A 'tidymodels' Engine and Other Extensions for the 'midr' Package |
|---|---|
| Description: | Provides a 'parsnip' engine for the 'midr' package, enabling users to fit, tune, and evaluate Maximum Interpretation Decomposition (MID) models within the 'tidymodels' framework. Developed through research by the Moonlight Seminar 2025, a study group of actuaries from the Institute of Actuaries of Japan, to enhance practical applications of interpretable modeling. Detailed methodology is available in Asashiba et al. (2025) <doi:10.48550/arXiv.2506.08338>. |
| Authors: | Ryoichi Asashiba [aut, cre] (ORCID: <https://orcid.org/0009-0001-9532-7000>) |
| Maintainer: | Ryoichi Asashiba <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.0.901 |
| Built: | 2026-10-09 13:00:51 UTC |
| Source: | https://github.com/ryo-asashi/midnight |
fastLmMatrix() estimates the linear model for multivariate response using one of several methods implemented using the Eigen linear algebra library.
fastLmMatrix(x, ...) ## Default S3 method: fastLmMatrix(x, y, tol = 1e-07, method = 0L, ...) ## S3 method for class 'formula' fastLmMatrix(formula, data = list(), method = 0L, ...)fastLmMatrix(x, ...) ## Default S3 method: fastLmMatrix(x, y, tol = 1e-07, method = 0L, ...) ## S3 method for class 'formula' fastLmMatrix(formula, data = list(), method = 0L, ...)
x |
a model matrix |
... |
optional parameters passed to methods. |
y |
the response matrix |
tol |
tolerance for the rank calculation. |
method |
an integer with value |
formula |
an object of class "formula" (or one that can be coerced to that class): a symbolic description of the model to be fitted. |
data |
an optional data frame, list or environment (or object coercible by |
fastLmMatrix() is a performance-optimized version of the standard lm.fit() function. Unlike RcppEigen::fastLm(), it is specifically designed to handle multivariate responses ( as a matrix).
It leverages the Eigen C++ template library for high-performance linear algebra, providing several decomposition methods with different trade-offs between speed and numerical stability.
fastLmMatrix() returns a list with the following components:
coefficients |
|
fitted.values |
|
residuals |
|
rank |
an integer giving the numeric rank of the model matrix |
The midnight package extends midr::ggmid() to provide modern distribution plots for MID feature importance.
Added types include sina, beeswarm, and violin plots.
## S3 method for class 'midimp' ggmid(object, type = NULL, theme = NULL, terms = NULL, max.nterms = 30, ...)## S3 method for class 'midimp' ggmid(object, type = NULL, theme = NULL, terms = NULL, max.nterms = 30, ...)
object |
a "midimp" object to be visualized. |
type |
the plotting style. In addition to standard types ("barplot", "boxplot", "dotchart", "heatmap"), this extended method supports "violinplot", "sinaplot", and "beeswarm". |
theme |
a character string or object defining the color theme. See |
terms |
an optional character vector specifying which terms to display. |
max.nterms |
an integer specifying the maximum number of terms to display. Defaults to 30. |
... |
optional parameters passed on to the layers. |
This is an S3 method for the midr::ggmid() generic for "midimp" objects created by midr::mid.importance().
This method replaces the primary layer with modern distribution geoms when type is one of the extended options.
ggmid.midimp() returns a "ggplot" object.
This S3 method is NOT registered automatically when the midnight package is loaded, and activated when nightfall() is explicitly called.
nightfall() activates the extended features provided by the midnight package.
It overrides specific S3 methods (such as ggmid.midimp), switches the underlying solvers to highly optimized Eigen-based routines via global options, and applies midnight-themed color palettes.
daybreak() reverses these changes, restoring the default behavior, solvers, and themes of the midr package.
nightfall(methods = TRUE, solvers = TRUE, themes = TRUE) daybreak(methods = TRUE, solvers = TRUE, themes = TRUE)nightfall(methods = TRUE, solvers = TRUE, themes = TRUE) daybreak(methods = TRUE, solvers = TRUE, themes = TRUE)
methods |
logical. If |
solvers |
logical. If |
themes |
logical. If |
nightfall() and daybreak() return an invisible list containing the previous options for solvers and themes.
Visualizes the combined effect of two variables from a "mid" object using a 3D perspective plot.
## S3 method for class 'mid' persp(x, pair, ..., resolution = c(50L, 50L))## S3 method for class 'mid' persp(x, pair, ..., resolution = c(50L, 50L))
x |
a "mid" object, typically the result of |
pair |
a character string or a character vector of length two specifying the variables to be plotted. |
... |
additional arguments passed on to |
resolution |
an integer or vector of two integers specifying the resolution of the evaluation grid for the x and y axes. Defaults to |
This is an S3 method for the persp() generic that plots a sum of effects for a "mid" object.
The plotted effects are inferred from the pair argument.
persp.mid() invisibly returns the viewing transformation matrix.
mid <- midr::interpret(mpg ~ wt * hp + factor(am), data = mtcars, lambda = .5) # Plot the sum of the main effects and their interaction persp(mid, pair = "wt*hp", theta = 210, phi = 20) # Plot only the interaction effect persp(mid, pair = "wt:hp", theta = 210, phi = 20) # Plot the additive main effects with a higher resolution persp(mid, pair = "wt+hp", resolution = 100L, theta = 210, phi = 20)mid <- midr::interpret(mpg ~ wt * hp + factor(am), data = mtcars, lambda = .5) # Plot the sum of the main effects and their interaction persp(mid, pair = "wt*hp", theta = 210, phi = 20) # Plot only the interaction effect persp(mid, pair = "wt:hp", theta = 210, phi = 20) # Plot the additive main effects with a higher resolution persp(mid, pair = "wt+hp", resolution = 100L, theta = 210, phi = 20)