| Title: | Discriminant Analysis with Permutation-Invariant Covariance Models |
|---|---|
| Description: | Extends classical linear and quadratic discriminant analysis by incorporating permutation-group symmetries into covariance matrix estimation. Methods based on the 'gips' framework identify and impose permutation structures that regularize covariance estimates and improve stability and interpretability for symmetric or exchangeable features. The package provides pooled and class-specific covariance models, including multi-class variants with shared or independently estimated symmetry structures. The underlying methodology is described by Graczyk et al. (2022) <doi:10.1214/22-AOS2174> and Chojecki, Morgen, and Kołodziejek (2025) <doi:10.18637/jss.v112.i07>. |
| Authors: | Antoni Zbigniew Kingston [aut], Norbert Maksymilian Frydrysiak [aut, cre], Adam Przemysław Chojecki [ctb] (ORCID: <https://orcid.org/0009-0008-2902-4096>) |
| Maintainer: | Norbert Maksymilian Frydrysiak <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 1.0.0 |
| Built: | 2026-11-01 07:57:20 UTC |
| Source: | https://github.com/antonikingston/gipsda |
Extract gips LDA discriminant coefficients
## S3 method for class 'gipslda' coef(object, ...)## S3 method for class 'gipslda' coef(object, ...)
object |
A fitted |
... |
Unused. |
The linear discriminant transformation matrix.
Linear discriminant analysis (LDA) using covariance matrices projected via the gips framework to enforce permutation symmetry and improve numerical stability.
gipslda(x, ...) ## S3 method for class 'formula' gipslda(formula, data, ..., subset, na.action) ## Default S3 method: gipslda(x, grouping, prior = proportions, tol = 1e-4, weighted_avg = FALSE, MAP = TRUE, optimizer = NULL, max_iter = NULL, show_progress_bar = FALSE, store_probabilities = TRUE, ...) ## S3 method for class 'data.frame' gipslda(x, ...) ## S3 method for class 'matrix' gipslda(x, grouping, ..., subset, na.action)gipslda(x, ...) ## S3 method for class 'formula' gipslda(formula, data, ..., subset, na.action) ## Default S3 method: gipslda(x, grouping, prior = proportions, tol = 1e-4, weighted_avg = FALSE, MAP = TRUE, optimizer = NULL, max_iter = NULL, show_progress_bar = FALSE, store_probabilities = TRUE, ...) ## S3 method for class 'data.frame' gipslda(x, ...) ## S3 method for class 'matrix' gipslda(x, grouping, ..., subset, na.action)
x |
(required if no formula is given as the principal argument) a matrix or data frame or Matrix containing the explanatory variables. |
... |
Arguments passed to or from other methods. |
formula |
A formula of the form |
data |
An optional data frame, list or environment from which variables
specified in |
grouping |
(required if no formula principal argument is given) a factor specifying the class for each observation. |
prior |
The prior probabilities of class membership. If unspecified, the class proportions for the training set are used. |
tol |
A tolerance to decide if a matrix is singular; variables whose
variance is less than |
subset |
An index vector specifying the cases to be used in the training sample. (NOTE: must be named.) |
na.action |
A function specifying the action for |
MAP |
Logical; whether to compute a Maximum A Posteriori
gips projection. If |
optimizer |
Character; optimization method used by gips
(e.g. |
max_iter |
Maximum number of iterations for the optimizer. |
show_progress_bar |
Logical; if |
store_probabilities |
Logical; if |
weighted_avg |
Logical; if |
This function is a minor modification of lda, replacing
the classical sample covariance estimators by projected covariance matrices
obtained using the gips framework.
Unlike classical LDA, the within-class covariance matrix is first projected onto a permutation-invariant structure using the gips framework. This can stabilize covariance estimation in high dimensions or when symmetry assumptions are justified.
The choice of optimizer and MAP estimation affects both the covariance estimate and the resulting discriminant directions.
See Chojecki et al. (2025) for theoretical background.
An object of class "gipslda" containing:
prior: prior class probabilities
counts: number of observations per class
means: group means
scaling: transformation matrix of linear discriminants
lev: class labels
svd: singular values of the between-class scatter
N: number of observations
optimization_info: estimated posterior probabilities of
retained permutations if stored; otherwise NULL
selected_map_permutation: MAP permutation selected by the
gips optimization and used for MAP covariance projection
call: matched call
Formula fits additionally contain terms, contrasts,
xlevels, and any recorded na.action.
This function is inspired by lda but is not
a drop-in replacement. The covariance estimator, optimization
procedure, and returned object differ substantially.
Chojecki, A., et al. (2025). Learning Permutation Symmetry of a Gaussian Vector with gips in R. Journal of Statistical Software, 112(7), 1–38. doi:10.18637/jss.v112.i07
Iris <- data.frame(rbind(iris3[, , 1], iris3[, , 2], iris3[, , 3]), Sp = rep(c("s", "c", "v"), rep(50, 3)) ) train <- sample(1:150, 75) z <- gipslda(Sp ~ ., Iris, prior = c(1, 1, 1) / 3, subset = train) predict(z, Iris[-train, ])$class (z1 <- update(z, . ~ . - Petal.W.))Iris <- data.frame(rbind(iris3[, , 1], iris3[, , 2], iris3[, , 3]), Sp = rep(c("s", "c", "v"), rep(50, 3)) ) train <- sample(1:150, 75) z <- gipslda(Sp ~ ., Iris, prior = c(1, 1, 1) / 3, subset = train) predict(z, Iris[-train, ])$class (z1 <- update(z, . ~ . - Petal.W.))
Quadratic Discriminant Analysis (QDA) in which each class covariance matrix participates in one joint gips projection, allowing the covariance matrices to share an estimated permutation symmetry.
gipsmultqda(x, ...) ## S3 method for class 'formula' gipsmultqda(formula, data, ..., subset, na.action) ## Default S3 method: gipsmultqda(x, grouping, prior = proportions, nu = 5, MAP = TRUE, optimizer = NULL, max_iter = NULL, show_progress_bar = FALSE, store_probabilities = TRUE, ...) ## S3 method for class 'data.frame' gipsmultqda(x, ...) ## S3 method for class 'matrix' gipsmultqda(x, grouping, ..., subset, na.action)gipsmultqda(x, ...) ## S3 method for class 'formula' gipsmultqda(formula, data, ..., subset, na.action) ## Default S3 method: gipsmultqda(x, grouping, prior = proportions, nu = 5, MAP = TRUE, optimizer = NULL, max_iter = NULL, show_progress_bar = FALSE, store_probabilities = TRUE, ...) ## S3 method for class 'data.frame' gipsmultqda(x, ...) ## S3 method for class 'matrix' gipsmultqda(x, grouping, ..., subset, na.action)
x |
(required if no formula is given as the principal argument) a matrix or data frame containing the explanatory variables. |
... |
Arguments passed to or from other methods. |
formula |
A formula of the form |
data |
An optional data frame, list or environment from which variables
specified in |
grouping |
(required if no formula is given) a factor specifying the class for each observation. |
prior |
Prior probabilities of class membership. If omitted, training-set class proportions are used. Supplied values must sum to one. |
nu |
Reserved for compatibility with related QDA interfaces; it is not currently used by the covariance projection. |
MAP |
Logical; if |
optimizer |
Character string specifying the optimization method used
for covariance projection. If |
max_iter |
Maximum number of iterations for stochastic optimizers. |
show_progress_bar |
Logical; if |
store_probabilities |
Logical; if |
subset |
An index vector specifying the cases to be used in the training sample. (NOTE: must be named.) |
na.action |
A function specifying the action to be taken if |
This function is a modification of qda in which the
class-specific covariance matrices are jointly projected to improve
numerical stability and exploit shared symmetry assumptions.
In contrast to classical QDA, which estimates each class covariance matrix
independently, gipsmultqda performs a joint projection of all class
covariance matrices using gips. This allows the
incorporation of shared permutation symmetries and can improve classification
performance in high-dimensional or small-sample regimes.
Several classification rules are available via
predict.gipsmultqda, including plug-in, predictive, debiased,
and leave-one-out cross-validation.
An object of class "gipsmultqda" containing:
prior: prior probabilities of the groups
counts: number of observations per group
means: group means
scaling: array of group-specific scaling matrices derived
from the projected covariance matrices
ldet: log-determinants of the projected covariance matrices
lev: class labels
N: total number of observations
optimization_info: estimated posterior probabilities of
retained permutations from the joint gips optimization
if stored; otherwise NULL
selected_map_permutation: MAP permutation selected by the
joint gips optimization and used for MAP covariance projection
call: the matched call
Formula fits additionally contain terms, contrasts,
xlevels, and any recorded na.action.
This function is not a drop-in replacement for qda.
The covariance estimation, returned object, and classification rules
differ substantially.
The theoretical background and details of covariance projection are
documented by gips and Chojecki et al. (2025).
qda, predict.gipsmultqda,
gipsqda, gipslda
tr <- sample(1:50, 25) train <- rbind(iris3[tr, , 1], iris3[tr, , 2], iris3[tr, , 3]) test <- rbind(iris3[-tr, , 1], iris3[-tr, , 2], iris3[-tr, , 3]) cl <- factor(c(rep("s", 25), rep("c", 25), rep("v", 25))) z <- gipsmultqda(train, cl) predict(z, test)$classtr <- sample(1:50, 25) train <- rbind(iris3[tr, , 1], iris3[tr, , 2], iris3[tr, , 3]) test <- rbind(iris3[-tr, , 1], iris3[-tr, , 2], iris3[-tr, , 3]) cl <- factor(c(rep("s", 25), rep("c", 25), rep("v", 25))) z <- gipsmultqda(train, cl) predict(z, test)$class
Quadratic discriminant analysis (QDA) using covariance matrices projected via the gips framework to enforce permutation symmetry and improve numerical stability.
gipsqda(x, ...) ## S3 method for class 'formula' gipsqda(formula, data, ..., subset, na.action) ## Default S3 method: gipsqda(x, grouping, prior = proportions, nu = 5, MAP = TRUE, optimizer = NULL, max_iter = NULL, show_progress_bar = FALSE, store_probabilities = TRUE, ...) ## S3 method for class 'data.frame' gipsqda(x, ...) ## S3 method for class 'matrix' gipsqda(x, grouping, ..., subset, na.action)gipsqda(x, ...) ## S3 method for class 'formula' gipsqda(formula, data, ..., subset, na.action) ## Default S3 method: gipsqda(x, grouping, prior = proportions, nu = 5, MAP = TRUE, optimizer = NULL, max_iter = NULL, show_progress_bar = FALSE, store_probabilities = TRUE, ...) ## S3 method for class 'data.frame' gipsqda(x, ...) ## S3 method for class 'matrix' gipsqda(x, grouping, ..., subset, na.action)
x |
(required if no formula is given as the principal argument) a matrix or data frame containing the explanatory variables. |
... |
Arguments passed to or from other methods. |
formula |
A formula of the form |
data |
An optional data frame, list or environment from which variables
specified in |
grouping |
(required if no formula is given) a factor specifying the class for each observation. |
prior |
The prior probabilities of class membership. If omitted, training-set class proportions are used. Supplied values must sum to one and match the number of groups. |
nu |
Reserved for compatibility with related QDA interfaces; it is not currently used by the covariance projection. |
MAP |
Logical; if |
optimizer |
Character string specifying the optimization method used
for covariance projection. If |
max_iter |
Maximum number of iterations for stochastic optimizers. |
show_progress_bar |
Logical; if |
store_probabilities |
Logical; if |
subset |
An index vector specifying the cases to be used in the training sample. (NOTE: must be named.) |
na.action |
A function specifying the action to be taken if |
This function is a minor modification of qda, replacing
the classical sample covariance estimators by projected covariance matrices
obtained using the gips framework.
Quadratic discriminant analysis models each class with its own covariance
matrix. In gipsqda, these covariance matrices are projected using the
gips framework, which enforces permutation symmetry and mitigates
singularity and overfitting in high-dimensional or small-sample settings.
Classification can be performed using plug-in, predictive, debiased,
or leave-one-out cross-validation rules via predict.gipsqda.
An object of class "gipsqda" containing the following components:
prior: prior probabilities of the groups
counts: number of observations in each group
means: group means
scaling: group-specific scaling matrices derived from the
projected covariance matrices
ldet: log-determinants of the projected covariance matrices
lev: class labels
N: total number of observations
optimization_info: named list of estimated posterior
probabilities of retained permutations, one element per class, if stored;
otherwise a named list of NULL values
selected_map_permutation: named list of MAP permutations
selected independently for each class
call: the matched call
Formula fits additionally contain terms, contrasts,
xlevels, and any recorded na.action.
The function may be called with either a formula interface or with a matrix
and grouping factor. Arguments subset and na.action, if used,
must be named.
Chojecki, A., et al. (2025). Learning Permutation Symmetry of a Gaussian Vector with gips in R. Journal of Statistical Software, 112(7), 1–38. doi:10.18637/jss.v112.i07
Venables, W. N. and Ripley, B. D. (2002). Modern Applied Statistics with S. Fourth edition. Springer.
qda, predict.gipsqda,
gipslda, lda
tr <- sample(1:50, 25) train <- rbind(iris3[tr, , 1], iris3[tr, , 2], iris3[tr, , 3]) test <- rbind(iris3[-tr, , 1], iris3[-tr, , 2], iris3[-tr, , 3]) cl <- factor(c(rep("s", 25), rep("c", 25), rep("v", 25))) z <- gipsqda(train, cl) predict(z, test)$classtr <- sample(1:50, 25) train <- rbind(iris3[tr, , 1], iris3[tr, , 2], iris3[tr, , 3]) test <- rbind(iris3[-tr, , 1], iris3[-tr, , 2], iris3[-tr, , 3]) cl <- factor(c(rep("s", 25), rep("c", 25), rep("v", 25))) z <- gipsqda(train, cl) predict(z, test)$class
Displays discriminant coordinates using either base graphics or a lattice scatterplot matrix.
## S3 method for class 'gipslda' pairs( x, labels = colnames(x), panel = panel.gipslda, dimen, abbrev = FALSE, ..., cex = 0.7, type = c("std", "trellis") )## S3 method for class 'gipslda' pairs( x, labels = colnames(x), panel = panel.gipslda, dimen, abbrev = FALSE, ..., cex = 0.7, type = c("std", "trellis") )
x |
A fitted |
labels |
Labels for discriminant dimensions. |
panel |
Panel function used by base graphics. |
dimen |
Maximum number of discriminant dimensions to display. |
abbrev |
Logical or integer controlling abbreviation of class labels. |
... |
Additional graphical arguments. |
cex |
Character expansion used by the default panel. |
type |
Either |
Invisibly returns NULL.
Displays training observations in discriminant space. One discriminant dimension is shown as class-wise histograms or densities, two dimensions as an equal-scale scatter plot, and higher dimensions as a pairs plot.
## S3 method for class 'gipslda' plot( x, panel = panel.gipslda, ..., cex = 0.7, dimen, abbrev = FALSE, xlab = "LD1", ylab = "LD2" )## S3 method for class 'gipslda' plot( x, panel = panel.gipslda, ..., cex = 0.7, dimen, abbrev = FALSE, xlab = "LD1", ylab = "LD2" )
x |
A fitted |
panel |
Panel function used for scatter plots. |
... |
Additional graphical arguments. |
cex |
Character expansion used by the default panel. |
dimen |
Maximum number of discriminant dimensions to display. |
abbrev |
Logical or integer controlling abbreviation of class labels. |
xlab, ylab
|
Axis labels. |
Invisibly returns NULL.
Computes class assignments, posterior probabilities, and linear discriminant coordinates for new observations.
## S3 method for class 'gipslda' predict( object, newdata, prior = object$prior, dimen, method = c("plug-in", "predictive", "debiased"), ... )## S3 method for class 'gipslda' predict( object, newdata, prior = object$prior, dimen, method = c("plug-in", "predictive", "debiased"), ... )
object |
A fitted |
newdata |
An optional matrix or data frame of observations. If omitted, the training data are reconstructed from the fitted call. |
prior |
Prior class probabilities used for prediction. |
dimen |
Number of discriminant dimensions to use. The default uses all
dimensions available in |
method |
Prediction rule: |
... |
Further arguments passed to or from methods. |
A list with class (predicted classes), posterior
(posterior class probabilities), and x (linear discriminant
coordinates).
Computes class assignments and posterior probabilities from a fitted
"gipsmultqda" model. Prediction rules match those of
predict.gipsqda; the fitted covariance estimates differ
because they were projected jointly.
## S3 method for class 'gipsmultqda' predict( object, newdata, prior = object$prior, method = c("plug-in", "predictive", "debiased", "looCV"), ... )## S3 method for class 'gipsmultqda' predict( object, newdata, prior = object$prior, method = c("plug-in", "predictive", "debiased", "looCV"), ... )
object |
A fitted |
newdata |
An optional matrix or data frame of observations. Omit this
argument when using |
prior |
Prior class probabilities used for prediction. |
method |
Prediction rule: |
... |
Further arguments passed to or from methods. |
A list with class (predicted classes) and posterior
(posterior class probabilities).
Computes class assignments and posterior probabilities from a fitted
"gipsqda" model.
## S3 method for class 'gipsqda' predict( object, newdata, prior = object$prior, method = c("plug-in", "predictive", "debiased", "looCV"), ... )## S3 method for class 'gipsqda' predict( object, newdata, prior = object$prior, method = c("plug-in", "predictive", "debiased", "looCV"), ... )
object |
A fitted |
newdata |
An optional matrix or data frame of observations. Omit this
argument when using |
prior |
Prior class probabilities used for prediction. |
method |
Prediction rule: |
... |
Further arguments passed to or from methods. |
A list with class (predicted classes) and posterior
(posterior class probabilities).
Prints the main components of a fitted gipsDA model, including the model
call, fitting options, group means, class counts, selected MAP permutation,
and posterior probabilities of retained permutations when stored.
## S3 method for class 'gipslda' print(x, ...) ## S3 method for class 'gipsqda' print(x, ...) ## S3 method for class 'gipsmultqda' print(x, ...)## S3 method for class 'gipslda' print(x, ...) ## S3 method for class 'gipsqda' print(x, ...) ## S3 method for class 'gipsmultqda' print(x, ...)
x |
A fitted gipsDA model. |
... |
Further arguments passed to printing methods. |
Invisibly returns x.
fit <- gipslda(Species ~ ., data = iris, optimizer = "BF") print(fit)fit <- gipslda(Species ~ ., data = iris, optimizer = "BF") print(fit)
Creates a compact summary object for a fitted gipsDA model. The summary
contains the most important fitted quantities and can be printed using the
corresponding print() method.
## S3 method for class 'gipslda' summary(object, ...) ## S3 method for class 'gipsqda' summary(object, ...) ## S3 method for class 'gipsmultqda' summary(object, ...)## S3 method for class 'gipslda' summary(object, ...) ## S3 method for class 'gipsqda' summary(object, ...) ## S3 method for class 'gipsmultqda' summary(object, ...)
object |
A fitted gipsDA model. |
... |
Further arguments passed to or from methods. |
An object of class "summary.gipsda". Common components include:
model: model type.
call: original model call.
n: number of observations used for fitting.
p: number of predictors.
groups: fitted class labels.
counts: class counts.
prior: prior class probabilities.
means: group means.
fit_info: fitting options, including MAP, optimizer,
max_iter, store_probabilities, and for LDA also weighted_avg.
optimization_info: stored posterior probabilities of retained
permutations, if available.
selected_map_permutation: selected MAP permutation or permutations.
LDA summaries additionally contain scaling, svd, and
proportion_trace. QDA summaries additionally contain scaling_dim
and ldet.
fit <- gipslda(Species ~ ., data = iris, optimizer = "BF") summary(fit) summary_object <- summary(fit) names(summary_object)fit <- gipslda(Species ~ ., data = iris, optimizer = "BF") summary(fit) summary_object <- summary(fit) names(summary_object)