| Title: | Stochastic Robust Multivariate Statistics |
|---|---|
| Description: | Algorithms for robust multivariate statistics (STochAstic Robust multivaRiate Statistics) including geometric median and geometric median covariance computation, k-medians clustering and robust median Principal Compenents Analysis (PCA), robust estimation of parameters for Gaussian, Student, or Laplace mixture models. 'STARRS' provides an independent, clean, consolidated and cohesive framework, while drawing inspiration from the approaches implemented in packages 'Gmedian', 'Kmedians', 'RGMM', 'RobRegression'. Methods used in the package refer to H. Robbins, S. Monro (1951) <doi:10.1214/aoms/1177729586>; D. Kraus, V. M. Panaretos (2012) <doi:10.1093/biomet/ass037>; H. Cardot, A. Godichon-Baggioni (2015) <doi:10.48550/arXiv.1504.02852>; A. Godichon-Baggioni, S. Robin (2024) <doi:10.1007/s11222-023-10362-9>. |
| Authors: | Antoine Godichon-Baggioni [aut, cph], Stéphane Robin [aut], Daphné Giorgi [aut, cre] |
| Maintainer: | Daphné Giorgi <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 1.0 |
| Built: | 2026-09-28 07:43:50 UTC |
| Source: | https://github.com/cran/STARRS |
Compute the median of a matrix X using the Averaged Stochastic Gradient algorithm
ASGMedian( X, init_median = NULL, weights = NULL, gamma = 2, alpha = 0.75, nstart = 1L, epsilon = 1e-08 )ASGMedian( X, init_median = NULL, weights = NULL, gamma = 2, alpha = 0.75, nstart = 1L, epsilon = 1e-08 )
X |
A numerical matrix corresponding to the data of size |
init_median |
Initial value of the median, by default equal to 0 (internally handled) |
weights |
Vector of size n of the weights, by default equal to 1 (internally handled) |
gamma |
ASG parameter (2 by default) |
alpha |
ASG parameter (0.75 by default) |
nstart |
Number of starts for the ASG algorithm, by default 1 |
epsilon |
Stopping criterion: the algorithm stops when the difference between two iterations is less than epsilon, by default 1e-08 |
The estimated median
N <- 1000 p <- 4 X <- matrix(rnorm(N*p),ncol=p) ASGMedian(X)N <- 1000 p <- 4 X <- matrix(rnorm(N*p),ncol=p) ASGMedian(X)
Compute the median covariation matrix of a matrix X using the Averaged Stochastic Gradient algorithm
ASGMedianCovariance( X, median_est = NULL, init_median_cov = NULL, weights = NULL, gamma = 2, alpha = 0.75, nstart = 1L )ASGMedianCovariance( X, median_est = NULL, init_median_cov = NULL, weights = NULL, gamma = 2, alpha = 0.75, nstart = 1L )
X |
A numerical matrix corresponding to the data of size |
median_est |
Estimation of the median |
init_median_cov |
Initial value of the median covariation matrix, by default equal to the identity matrix (internally handled) |
weights |
Vector of size $n$ of the weights, by default equal to 1 (internally handled) |
gamma |
ASG parameter (2 by default) |
alpha |
ASG parameter (0.75 by default) |
nstart |
Number of starts for the ASG algorithm, by default 1 |
The estimated median covariation matrix
N <- 1000 p <- 4 X <- matrix(rnorm(N*p),ncol=p) med <- ASGMedian(X) ASGMedianCovariance(X, median_est=med)N <- 1000 p <- 4 X <- matrix(rnorm(N*p),ncol=p) med <- ASGMedian(X) ASGMedianCovariance(X, median_est=med)
Robust PCA using ASG algorithm for the median and the median covariation computation
ASGRobustPCA( X, init_median = rep(0, ncol(X)), init_median_cov = diag(ncol(X)), weights = rep(1, nrow(X)), epsilon = 1e-08, scores = 2, gamma = 2, alpha = 0.75, nstart = 1 )ASGRobustPCA( X, init_median = rep(0, ncol(X)), init_median_cov = diag(ncol(X)), weights = rep(1, nrow(X)), epsilon = 1e-08, scores = 2, gamma = 2, alpha = 0.75, nstart = 1 )
X |
Matrix of size N*p corresponding to the data. The rows are the observations. |
init_median |
Initial value of the median, by default equal to 0 |
init_median_cov |
Initial value of the median covariation matrix, by default equal to the identity matrix |
weights |
Vector of size N of the weights, by default equal to 1 |
epsilon |
Stopping criterion: the algorithm stops when the difference between two iterations is less than epsilon, by default 1e-08 |
scores |
Number of scores to compute, by default 2 |
gamma |
ASG parameter (2 by default) |
alpha |
ASG parameter (0.75 by default) |
nstart |
Number of starts for the ASG algorithm, by default 1 |
A list containing :
median : the estimated median
covmedian : the estimated median covariation matrix
scores : the scores
vectors: the eigen vectors
N <- 1000 p <- 4 X <- matrix(rnorm(N*p),ncol=p) ASGRobustPCA(X)N <- 1000 p <- 4 X <- matrix(rnorm(N*p),ncol=p) ASGRobustPCA(X)
Given the eigen values of the median covariation matrix, this function estimates
the eigen values of a variance-covariance matrix using the fix point method and Monte Carlo approximation.
fixMC( U, delta, init = NULL, niter = 10L, epsilon = 1e-08, out_index = as.integer(c()) )fixMC( U, delta, init = NULL, niter = 10L, epsilon = 1e-08, out_index = as.integer(c()) )
U |
Matrix of size N*p corresponding to - In a gaussian model typically 'U = matrix(rnorm(N*p),ncol=p)' - In a Student model 'U <- matrix(rnorm(N*p)/sqrt(rchisq(1,df=df))*sqrt((df-2)), ncol=p))' - In a Laplace model 'U <- LaplacesDemon::rmvl(N,mu=rep(0,p),Sigma=diag(p))' |
delta |
Vector of size p of the eigen values of the median covariation matrix |
init |
Initial value of the vector of eigen values of the variance-covariance matrix, by default equal to delta (internally handled) |
niter |
Maximum number of iterations for the gradient descent algorithm, by default 10 |
epsilon |
Stopping criterion: the algorithm stops when the difference between two iterations is less than epsilon, by default 1e-08 |
out_index |
Indexes of the iterations for which we want to output the values of the estimates, default is the last iteration |
The vector of the estimated eigen values
delta <- c(1, 1) N <- 1000 p <- length(delta) U <- matrix(rnorm(N*p),ncol=p) gradMC(U=U,delta=delta)delta <- c(1, 1) N <- 1000 p <- length(delta) U <- matrix(rnorm(N*p),ncol=p) gradMC(U=U,delta=delta)
We consider a Gaussian random vector
with , and generate a sample of size .
To investigate the robustness of the estimators, an increasing fraction of the observations,
varying from to , is replaced by outliers drawn from a multivariate Student distribution and scaled by a factor of .
gaussStudentCont_n5000_d5gaussStudentCont_n5000_d5
List of contaminated (, , , ,,) data,
each item being a list of 2 :
X : data matrix
C : -dimensional binary vector indicating which observation is an outlier
Synthetic data set
A set of observations with dimension , equally
spread into , each being sampled from a multivariate Gaussian distribution
(with ). The mean vectors are set to
(where stands for the d-dimensional vector filled with ones) and the variance matrices to
,
( being the -dimensional identity matrix).
In addition, we consider that a fraction of the genuine observations have been replaced
with observations arising from a mixture with components of student distribution,
with same respective location and scale parameters and with degree of freedom 1.
GMMcontStudentGMMcontStudent
Output of the function GMMcontStudent
Given the eigen values of the median covariation matrix, this function estimates
the eigen values of a variance-covariance matrix using the gradient descent method and Monte Carlo approximation.
gradMC( U, delta, init = NULL, niter = 10L, epsilon = 1e-08, step = as.numeric(c()), out_index = as.integer(c()) )gradMC( U, delta, init = NULL, niter = 10L, epsilon = 1e-08, step = as.numeric(c()), out_index = as.integer(c()) )
U |
Matrix of size N*p corresponding to - In a gaussian model typically 'U = matrix(rnorm(N*p),ncol=p)' - In a Student model 'U <- matrix(rnorm(N*p)/sqrt(rchisq(1,df=df))*sqrt((df-2)), ncol=p))' - In a Laplace model 'U <- LaplacesDemon::rmvl(N,mu=rep(0,p),Sigma=diag(p))' |
delta |
Vector of size p of the eigen values of the median covariation matrix |
init |
Initial value of the vector of eigen values of the variance-covariance matrix, by default equal to delta (internally handled) |
niter |
Maximum number of iterations for the gradient descent algorithm, by default 10 |
epsilon |
Stopping criterion: the algorithm stops when the difference between two iterations is less than epsilon, by default 1e-08 |
step |
Step of the gradient descent, by default 1 |
out_index |
Indexes of the iterations for which we want to output the values of the estimates, default is the last iteration |
A list containing the estimated eigen values
and the values of the estimates for different iterations
delta <- c(1, 1) N <- 1000 p <- length(delta) U <- matrix(rnorm(N*p),ncol=p) gradMC(U=U,delta=delta)delta <- c(1, 1) N <- 1000 p <- length(delta) U <- matrix(rnorm(N*p),ncol=p) gradMC(U=U,delta=delta)
We consider a set of observations with dimension , equally spread into ,
each being sampled from a multivariate Gaussian distribution (with ),
with respective mean vector and variance matrix .
The mean vectors are set to
(where stands for the -dimensional vector filled with ones) and the variance matrices to
.
heteroGMMStudentCont_K3_d5_n1500heteroGMMStudentCont_K3_d5_n1500
List of contaminated (, , , ,,) data,
each item being a list of 3 :
: data matrix
: -dimensional vector indicating to which cluster each data belongs
: -dimensional binary vector indicating which observation is an outlier
We consider a set of observations with dimension , equally spread into ,
each being sampled from a multivariate Gaussian distribution (with ),
with respective mean vector and variance matrix .
The mean vectors are set to
(where stands for the -dimensional vector filled with ones)
and all variance matrices are equal:
.
homoGMMStudentCont_K3_d5_n1500homoGMMStudentCont_K3_d5_n1500
List of contaminated (, , , ,,) data,
each item being a list of 3 :
: data matrix
: -dimensional vector indicating to which cluster each data belongs
: -dimensional binary vector indicating which observation is an outlier
Perform k-medians clustering on a data matrix.
kmedians( X, nclust = 1:15, ninit = 0, niter = 20, method = "Offline", init = TRUE, nb_cores = 1 )kmedians( X, nclust = 1:15, ninit = 0, niter = 20, method = "Offline", init = TRUE, nb_cores = 1 )
X |
A numerical matrix giving the data |
nclust |
A vector of positive integers giving the possible numbers of clusters. Default is |
ninit |
A non negative integer giving the number of random initializations. Default is |
niter |
A positive integer giving the number of iterations for the EM algorithms. Default is |
method |
The selected method for the K-medians algorithm. Can be
|
init |
A logical argument telling if the function |
nb_cores |
Number of cores in parallel computation, by default 1 |
List with the following components :
bestresults: A list giving all the results for the clustering selected by 'capushe'.
cluster A vector of positive integers giving the clustering.
centers A numerical matrix giving the centers of the clusters.
SE An integer giving the Sum of Errors.
allresults: A list containing all the results.
SE: A vector giving the Sum of Errors for each considered number of clusters.
cap: The results given by the function 'capushe' if nclust is of length larger than 10.
Kopt: An integer giving the number of clusters selected by 'capushe' if nclust is of length larger than 10.
Godichon-Baggioni, A. and Surendran, S. A penalized criterion for selecting the number of clusters for K-medians. arxiv.org/abs/2209.03597
n <- 1000 K <- 3 pcont <- 0.2 sphereGM <- rSphereGM(n=n,K=K,pcont=pcont) X <-sphereGM$X res <- kmedians(X) plot(X, col=res$bestresult$cluster)n <- 1000 K <- 3 pcont <- 0.2 sphereGM <- rSphereGM(n=n,K=K,pcont=pcont) X <-sphereGM$X res <- kmedians(X) plot(X, col=res$bestresult$cluster)
Robust EM algorithm for Mixture Model for a number of clusters in a range
multipleRobustMM( X, nclust = 2:5, ninit = 10, init = "Mclust", methodMC = "RobbinsMC", methodMCM = "Weiszfeld", model = "Gaussian", df = NULL, niterWiesz = 50, niterEM = 50, niterMC = 50, sizeMC = 1000, logLikeInit = -1e+10, eps_dist = 1e-04, eps_eigval = 1e-10, eps_MCM_MC = 0.001, eps_tau = 1e-04, logPhiTol = -20, outlierThreshold = -20, gammaRMC = 0.75, cRMC = ncol(X), wRMC = 2, scale = FALSE, criterion = "BIC", nb_cores = parallel::detectCores() )multipleRobustMM( X, nclust = 2:5, ninit = 10, init = "Mclust", methodMC = "RobbinsMC", methodMCM = "Weiszfeld", model = "Gaussian", df = NULL, niterWiesz = 50, niterEM = 50, niterMC = 50, sizeMC = 1000, logLikeInit = -1e+10, eps_dist = 1e-04, eps_eigval = 1e-10, eps_MCM_MC = 0.001, eps_tau = 1e-04, logPhiTol = -20, outlierThreshold = -20, gammaRMC = 0.75, cRMC = ncol(X), wRMC = 2, scale = FALSE, criterion = "BIC", nb_cores = parallel::detectCores() )
X |
A numerical matrix giving the data of size nxd |
nclust |
Range of number of clusters |
ninit |
The number of random initializations (10 by default) |
init |
Kind of initialization, can be 'Mclust' (default) or 'genie' |
methodMC |
Method to compute the eigen values and vectors of variance-covariance matrix starting from median covariation matrix, can be "FixMC", "GradMC" or "RobbinsMC" (by default) |
methodMCM |
Method to compute the geometric median and the median covariation matrix, can be "Weiszfeld" (by default) or "ASG" |
model |
Type of distribution: can be "Gaussian" (by default), "Student" or "Laplace" |
df |
Degrees of freedom used when model is 'Student' (NULL by default). When used, it must be greater than 3 |
niterWiesz |
Maximum number of iterations in the geometric median computation using the Weiszfeld algorithm |
niterEM |
Maximum number of updates in the EM algorithm |
niterMC |
Maximum number of updates in the gradient descent algorithm in the estimation of the eigen values of the variance-covariance matrix |
sizeMC |
Size of the sample for the Monte Carlo method in the estimation of the eigen values of the variance-covariance matrix |
logLikeInit |
Initial value of log likelihood |
eps_dist |
Distance between old and new centers after each iteration has to be greater than eps_dist |
eps_eigval |
Minimal value for eigen values (1e-10 by default) |
eps_MCM_MC |
Stopping criterion used in the Weiszfeld geometric median computation and in the estimation of the eigen values of the variance-covariance matrix |
eps_tau |
Small correction to avoid 0 and 1 values in tau computation (1e-04 by default) |
logPhiTol |
Tolerance for small values of log densities (-20 by default) |
outlierThreshold |
Threshold for outliers detection (-20 by default) |
gammaRMC |
Robbins-Monro parameter for eigen values estimation, if methodMC="RobbinsMC" |
cRMC |
Robbins-Monro parameter for eigen values estimation, if methodMC="RobbinsMC". When parameter scale=TRUE, cRMC=1 should be a good choice. |
wRMC |
Robbins-Monro parameter for eigen values estimation, if methodMC="RobbinsMC" |
scale |
Boolean value for scaling data before running the algorithm (FALSE by default) |
criterion |
Criterion for choice of best clustering, can be 'ICL' or 'BIC' (default) |
nb_cores |
Number of cores in parallel computation, by default parallel::detectCores() |
An object of class RMM, which is a list with the following components:
A list containing the results from the RobustMM function for each number of classes specified in nclust.
A list corresponding to the output of RobustMM for the best model selected using the BIC or ICL criterion.
A numeric vector of length length(nclust) containing the Integrated Complete-data Likelihood values for the different models.
A numeric vector of length length(nclust) containing the Bayesian Information Criterion values for the different models.
The original data matrix X.
An integer vector specifying the number of classes (models) considered.
The optimal number of classes selected based on the BIC or ICL criterion.
https://cnrs.hal.science/hal-03853744/
Cardot, H., Cenac, P. and Zitt, P-A. (2013). Efficient and fast estimation of the geometric median in Hilbert spaces with an averaged stochastic gradient algorithm. Bernoulli, 19, 18-43.
Cardot, H. and Godichon-Baggioni, A. (2017). Fast Estimation of the Median Covariation Matrix with Application to Online Robust Principal Components Analysis. Test, 26(3), 461-480
Vardi, Y. and Zhang, C.-H. (2000). The multivariate L1-median and associated data depth. Proc. Natl. Acad. Sci. USA, 97(4):1423-1426.
Given a data set X, this function estimates robustly variance-covariance matrix via the geometric median and the Median Covariation Matrix.
offlineRobustVariance( X, methodMC = "RobbinsMC", methodMCM = "Weiszfeld", model = "Gaussian", df = NULL, computeOutliers = FALSE, cutoff = stats::qchisq(p = 0.95, df = ncol(X)), init_median = rep(0, ncol(X)), init_median_cov = diag(ncol(X)), niterWeisz = 50, niterMC = 50, sizeMC = 1000, epsMCM = 1e-08, epsMC = 1e-08, eps_eigval = 1e-04, eps_lambda = 1e-04, gammaMCM = 2, alphaMCM = 0.75, nstart = 1, gammaRMC = 0.75, cRMC = 2, wRMC = 2 )offlineRobustVariance( X, methodMC = "RobbinsMC", methodMCM = "Weiszfeld", model = "Gaussian", df = NULL, computeOutliers = FALSE, cutoff = stats::qchisq(p = 0.95, df = ncol(X)), init_median = rep(0, ncol(X)), init_median_cov = diag(ncol(X)), niterWeisz = 50, niterMC = 50, sizeMC = 1000, epsMCM = 1e-08, epsMC = 1e-08, eps_eigval = 1e-04, eps_lambda = 1e-04, gammaMCM = 2, alphaMCM = 0.75, nstart = 1, gammaRMC = 0.75, cRMC = 2, wRMC = 2 )
X |
Matrix of size n*p corresponding to the data. The rows are the observations. |
methodMC |
Method to estimate the eigenvalues of the variance: can be "FixMC", "GradMC" and "RobbinsMC" (by default). |
methodMCM |
Method for estimating the Median Covariation Matrix: can be "Weiszfeld" (by default) or "ASG". |
model |
Type of distribution: can be "Gaussian" (by default), "Student" or "Laplace" |
df |
Number of degrees of freedom if model='Student'. |
computeOutliers |
Flag for outliers computation, FALSE by default. |
cutoff |
Threshold at which a data item is considered contaminated (if computeOutliers is TRUE). Default is |
init_median |
A row vector for initializing the estimates of the median. Default is rep(0,ncol(X)). |
init_median_cov |
A matrix for initializing the estimates of the MCM. Default is Identity. |
niterWeisz |
The maximum number of iteration for the Weiszfeld algorithm. Default is 50. |
niterMC |
Maximum number of iterations is MethodMC='FixMC' or 'GradMC'. |
sizeMC |
Number of data generated in the Monte Carlo procedure to estimate the eigenvalues of the variance. Default is batch. |
epsMCM |
Stopping criterion for Weiszfeld algorithm: the algorithm stops when the difference between two iterations is less than epsilon, by default 1e-08 |
epsMC |
Stopping criterion for MethodMC algorithm: the algorithm stops when the difference between two iterations is less than epsilon, by default 1e-08 |
eps_eigval |
Minimal value for eigen values (1e-04 by default) |
eps_lambda |
Minimal value for estimated eigen values (1e-04 by default) |
gammaMCM |
A positive constant if methodMCM='ASG'. |
alphaMCM |
A positive constant if methodMCM='ASG'. Must belong to (0,1). |
nstart |
Number of run if methodMCM='ASG'. |
gammaRMC |
Robbins-Monro parameter for eigen values estimation, if methodMCM="RobbinsMC". |
cRMC |
Robbins-Monro parameter for eigen values estimation, if methodMCM="RobbinsMC". |
wRMC |
Robbins-Monro parameter for eigen values estimation, if methodMCM="RobbinsMC". |
A list with the following components:
A robust estimate of the variance.
If required, a binary vector of length nrow(X) indicating outliers (1 = outlier, 0 = inlier). Outlier detection is based on Mahalanobis distance.
If required, a numeric vector of length nrow(X) giving the Mahalanobis distances of each observation from the estimated center.
N <- 1000 p <- 10 X <- matrix(rnorm(N*p),ncol=p) offlineRobustVariance(X=X)N <- 1000 p <- 10 X <- matrix(rnorm(N*p),ncol=p) offlineRobustVariance(X=X)
Given a data set X, this function estimates online and robustly variance-covariance matrix via the geometric median and the Median Covariation Matrix.
onlineRobustVariance( X, nDataInit = 100, model = "Gaussian", df = NULL, computeOutliers = FALSE, cutoff = stats::qchisq(p = 0.95, df = ncol(X)), batch = ncol(X), niterWeisz = 100, sizeMC = batch, epsilon = 1e-08, eps_eigval = 1e-04, eps_lambda = 1e-04, gamma = 0.75, c = sqrt(ncol(X)), gammaRMC = 0.75, cRMC = ncol(X), wRMC = 2 )onlineRobustVariance( X, nDataInit = 100, model = "Gaussian", df = NULL, computeOutliers = FALSE, cutoff = stats::qchisq(p = 0.95, df = ncol(X)), batch = ncol(X), niterWeisz = 100, sizeMC = batch, epsilon = 1e-08, eps_eigval = 1e-04, eps_lambda = 1e-04, gamma = 0.75, c = sqrt(ncol(X)), gammaRMC = 0.75, cRMC = ncol(X), wRMC = 2 )
X |
Matrix of size n*d corresponding to the data. The rows are the observations. |
nDataInit |
Number of data used for initializing the algorithm. Default is 100. |
model |
Type of distribution: can be "Gaussian" (by default), "Student" or "Laplace" |
df |
Number of degrees of freedom if model='Student'. |
computeOutliers |
Flag for outliers computation, FALSE by default. If TRUE, only Gaussian model is possible. |
cutoff |
Threshold at which a data item is considered contaminated (if computeOutliers is TRUE). Default is |
batch |
Size of the batch. Default is ncol(X). |
niterWeisz |
Maximum number of iterations for first estimation of the median and the Median Covariation Matrix with the help of Weiszfeld algorithm. Default is 100. |
sizeMC |
Number of data generated in the Monte Carlo procedure to estimate the eigenvalues of the variance. Default is batch. |
epsilon |
Stopping criterion for RobbinsMC and Weisfeld algorithms: the algorithms stop when the difference between two iterations is less than epsilon, by default 1e-08 |
eps_eigval |
Minimal value for eigen values (1e-04 by default) |
eps_lambda |
Minimal value for estimated eigen values (1e-04 by default) |
gamma |
Stochastic gradient parameter (0.75 by default). Must belong to (0,1). |
c |
Stochastic gradient parameter ( |
gammaRMC |
A parameter of the function RobbinsMC. |
cRMC |
A parameter of the function RobbinsMC. |
wRMC |
A parameter of the function RobbinsMC. |
A list with the following components:
A robust estimate of the variance.
If required, a binary vector of length nrow(X) indicating outliers (1 = outlier, 0 = inlier). Outlier detection is based on Mahalanobis distance.
If required, a numeric vector of length nrow(X) giving the Mahalanobis distances of each observation from the estimated center.
N <- 1000 p <- 10 X <- matrix(rnorm(N*p),ncol=p) onlineRobustVariance(X=X)N <- 1000 p <- 10 X <- matrix(rnorm(N*p),ncol=p) onlineRobustVariance(X=X)
Plot method for Robust Mixture Model
## S3 method for class 'RMM' plot( x, showOutliers = FALSE, what = c("Two_Dim", "Two_Dim_Uncertainty", "ICL", "BIC", "Profiles", "Uncertainty"), K = NULL, ... )## S3 method for class 'RMM' plot( x, showOutliers = FALSE, what = c("Two_Dim", "Two_Dim_Uncertainty", "ICL", "BIC", "Profiles", "Uncertainty"), K = NULL, ... )
x |
An object of class |
showOutliers |
Logical. If FALSE (by default), outliers are removed from the plot |
what |
Character vector. The type of plot to be displayed. Possible values are:
|
K |
Integer. The number of clusters to be displayed. If NULL (by default), the best result is displayed |
... |
Additional parameters |
A plot for each item in the what parameter
print method for class RMM.
## S3 method for class 'RMM' print(x, ...)## S3 method for class 'RMM' print(x, ...)
x |
Object of class |
... |
Additional arguments affecting the summary produced. |
Print of output of a call to multipleRobustMM function
Function to generate a sample of a gaussian mixture model with Student contamination
, where .
rGMMcontStudent(nk, muG, sigmaG, delta, dfT, muT, sigmaT)rGMMcontStudent(nk, muG, sigmaG, delta, dfT, muT, sigmaT)
nk |
Vector of the number of observations in each component, giving the proportions |
muG |
Matrix of the means of the Gaussian components |
sigmaG |
Array of the variance-covariance matrices of the Gaussian components |
delta |
Proportion of contamination |
dfT |
Degrees of freedom of the Student contamination |
muT |
Matrix of the means of the Student contamination |
sigmaT |
Array of the variances of the Student contamination |
A list containing the sample X, the indicator of contamination C and the latent variable Z, giving the classification
# Dimensions K <- 3; nk <- rep(500, K); d <- 5 # Gaussian parameters mu <- rbind(mu1=rep(0, d), mu2=rep(3, d), mu3=rep(-3, d)) sigma <- array(dim=c(K, d, d)) sigma[1, , ] <- 2*diag(d); sigma[2, , ] <- diag(1:d); sigma[3, , ] <- diag(1/(1:d)) # Student contamination fraction <- 0.3 dfT <- 1; dfT <- 1; muT <- mu; sigmaT <- sigma # Simulation GMMcontStudent <- rGMMcontStudent(nk=nk, muG=mu, sigmaG=sigma, delta=fraction, dfT=dfT, muT=muT, sigmaT=sigmaT)# Dimensions K <- 3; nk <- rep(500, K); d <- 5 # Gaussian parameters mu <- rbind(mu1=rep(0, d), mu2=rep(3, d), mu3=rep(-3, d)) sigma <- array(dim=c(K, d, d)) sigma[1, , ] <- 2*diag(d); sigma[2, , ] <- diag(1:d); sigma[3, , ] <- diag(1/(1:d)) # Student contamination fraction <- 0.3 dfT <- 1; dfT <- 1; muT <- mu; sigmaT <- sigma # Simulation GMMcontStudent <- rGMMcontStudent(nk=nk, muG=mu, sigmaG=sigma, delta=fraction, dfT=dfT, muT=muT, sigmaT=sigmaT)
Function to generate a sample of a gaussian mixture model with uniform contamination
, where .
rGMMcontUniform(nk, muG, sigmaG, delta, lUnif, uUnif)rGMMcontUniform(nk, muG, sigmaG, delta, lUnif, uUnif)
nk |
Vector of the number of observations in each component, giving the proportions |
muG |
Matrix of the means of the Gaussian components |
sigmaG |
Array of the variance-covariance matrices of the Gaussian components |
delta |
Proportion of contamination |
lUnif |
Vector of lower bounds of the uniform contamination |
uUnif |
Vector of upper bounds of the uniform contamination |
A list containing the sample X, the indicator of contamination C and the latent variable Z, giving the classification
# Dimensions K <- 3; nk <- rep(500, K); d <- 5 # Gaussian parameters mu <- rbind(mu1=rep(0, d), mu2=rep(3, d), mu3=rep(-3, d)) sigma <- array(dim=c(K, d, d)) sigma[1, , ] <- 2*diag(d); sigma[2, , ] <- diag(1:d); sigma[3, , ] <- diag(1/(1:d)) # Student contamination fraction <- 0.3 lower <- rep(0,d); upper <- rep(1,d) # Simulation GMMcontUniform <- rGMMcontUniform(nk=nk, muG=mu, sigmaG=sigma, delta=fraction, lUnif=lower, uUnif=upper)# Dimensions K <- 3; nk <- rep(500, K); d <- 5 # Gaussian parameters mu <- rbind(mu1=rep(0, d), mu2=rep(3, d), mu3=rep(-3, d)) sigma <- array(dim=c(K, d, d)) sigma[1, , ] <- 2*diag(d); sigma[2, , ] <- diag(1:d); sigma[3, , ] <- diag(1/(1:d)) # Student contamination fraction <- 0.3 lower <- rep(0,d); upper <- rep(1,d) # Simulation GMMcontUniform <- rGMMcontUniform(nk=nk, muG=mu, sigmaG=sigma, delta=fraction, lUnif=lower, uUnif=upper)
Given the eigen values of the median covariation matrix, this function estimates
the eigen values of a variance-covariance matrix using the Robbins-Monro method and Monte Carlo approximation.
robbinsMC( U, delta, init = NULL, gamma = 0.75, c = 2, w = 2, c_bar = 0, c_tilde = 0, sumlog = 1, epsilon = 1e-08 )robbinsMC( U, delta, init = NULL, gamma = 0.75, c = 2, w = 2, c_bar = 0, c_tilde = 0, sumlog = 1, epsilon = 1e-08 )
U |
Matrix of size N*p corresponding to - In a gaussian model typically 'U = matrix(rnorm(N*p),ncol=p)' - In a Student model 'U <- matrix(rnorm(N*p)/sqrt(rchisq(1,df=df))*sqrt((df-2)), ncol=p))' - In a Laplace model 'U <- LaplacesDemon::rmvl(N,mu=rep(0,p),Sigma=diag(p))' |
delta |
Vector of size p of the eigen values of the median covariation matrix |
init |
Initial value of the vector of eigen values of the variance-covariance matrix, by default equal to delta (internally handled) |
gamma |
Robbins-Monro parameter (0.75 by default) |
c |
Robbins-Monro parameter (2 by default) |
w |
Robbins-Monro parameter (2 by default) |
c_bar |
Hyperparameter for fine tuning. Do not change unless you are an experienced user (0 by default) |
c_tilde |
Hyperparameter for fine tuning. Do not change unless you are an experienced user (0 by default) |
sumlog |
Hyperparameter for fine tuning. Do not change unless you are an experienced user (1 by default) |
epsilon |
Stopping criterion: the algorithm stops when the difference between two iterations is less than epsilon, by default 1e-08 |
The vector of the estimated eigen values
delta <- c(1, 1) N <- 1000 p <- length(delta) U <- matrix(rnorm(N*p),ncol=p) robbinsMC(U=U,delta=delta)delta <- c(1, 1) N <- 1000 p <- length(delta) U <- matrix(rnorm(N*p),ncol=p) robbinsMC(U=U,delta=delta)
Output of robust clustering on synthetic data set GMMcontStudent
robustGMMOutputrobustGMMOutput
Output of the call to the robust clustering function multipleRobustMM(GMMcontStudent$X, nclust=1:5)
Robust EM algorithm for Mixture Model for a fixed number of clusters K
robustMM( X, K = 2, ninit = 10, initClust = NULL, methodMC = "RobbinsMC", methodMCM = "Weiszfeld", model = "Gaussian", df = NULL, niterWiesz = 50, niterEM = 50, niterMC = 50, sizeMC = 1000, logLikeInit = -1e+10, eps_dist = 1e-04, eps_eigval = 1e-10, eps_MCM_MC = 0.001, eps_tau = 1e-04, logPhiTol = -20, outlierThreshold = -20, gammaRMC = 0.75, cRMC = ncol(X), wRMC = 2, scale = FALSE, verbose = TRUE )robustMM( X, K = 2, ninit = 10, initClust = NULL, methodMC = "RobbinsMC", methodMCM = "Weiszfeld", model = "Gaussian", df = NULL, niterWiesz = 50, niterEM = 50, niterMC = 50, sizeMC = 1000, logLikeInit = -1e+10, eps_dist = 1e-04, eps_eigval = 1e-10, eps_MCM_MC = 0.001, eps_tau = 1e-04, logPhiTol = -20, outlierThreshold = -20, gammaRMC = 0.75, cRMC = ncol(X), wRMC = 2, scale = FALSE, verbose = TRUE )
X |
A numerical matrix giving the data of size nxd |
K |
Integer giving the number of clusters |
ninit |
The number of random initializations (10 by default) |
initClust |
Initial clustering, typically an output of |
methodMC |
Method to compute the eigen values and vectors of variance-covariance matrix starting from median covariation matrix, can be "FixMC", "GradMC" or "RobbinsMC" (by default) |
methodMCM |
Method to compute the geometric median and the median covariation matrix, can be "Weiszfeld" (by default) or "ASG" |
model |
Type of distribution: can be "Gaussian" (by default), "Student" or "Laplace" |
df |
Degrees of freedom used when model is 'Student' ( |
niterWiesz |
Maximum number of iterations in the geometric median computation using the Weiszfeld algorithm (50 by default) |
niterEM |
Maximum number of updates in the EM algorithm (50 by default) |
niterMC |
Maximum number of updates in the gradient descent algorithm in the estimation of the eigen values of the variance-covariance matrix (50 by default) |
sizeMC |
Size of the sample for the Monte Carlo method in the estimation of the eigen values of the variance-covariance matrix (1000 by default) |
logLikeInit |
Initial value of log likelihood (-1e10 by default). |
eps_dist |
Distance between old and new centers after each iteration has to be greater than eps_dist (1e-04 by default) |
eps_eigval |
Minimal value for eigen values (1e-10 by default) |
eps_MCM_MC |
Stopping criterion used in the Weiszfeld geometric median computation and in the estimation of the eigen values of the variance-covariance matrix |
eps_tau |
Small correction to avoid 0 and 1 values of tau (1e-04 by default) |
logPhiTol |
Tolerance for small values of log densities (-20 by default). This must be a negative value, since the log densities are first adjusted by substracting their max. |
outlierThreshold |
Threshold for outliers detection, on a log density criterion (-20 by default) |
gammaRMC |
Robbins-Monro parameter for eigen values estimation, if methodMC="RobbinsMC" |
cRMC |
Robbins-Monro parameter for eigen values estimation, if methodMC="RobbinsMC". When parameter |
wRMC |
Robbins-Monro parameter for eigen values estimation, if methodMC="RobbinsMC" |
scale |
Boolean value for scaling data before running the algorithm ( |
verbose |
Boolean value for printing execution messages |
A list with the following components:
A numeric matrix of size K × ncol(X), where each row corresponds to the center of a class.
A numeric array of size K × ncol(X) × ncol(X) containing the covariance matrices for each class.
The log-likelihood of the selected model.
The entropy of the selected model.
A numeric matrix of size n × K, where each row contains the posterior probabilities of class membership for each observation.
An integer vector of length nrow(X) indicating the assigned class for each observation.
The total number of iterations performed.
The initialization used by the EM algorithm.
A numeric vector of length K giving the estimated proportion of each class.
A binary vector of length nrow(X) where a value of 1 indicates that the corresponding observation is considered as an outlier. An observation is flagged as an outlier if its log-likelihood under all classes is below outlierThreshold.
https://cnrs.hal.science/hal-03853744/
Cardot, H., Cenac, P. and Zitt, P-A. (2013). Efficient and fast estimation of the geometric median in Hilbert spaces with an averaged stochastic gradient algorithm. Bernoulli, 19, 18-43.
Cardot, H. and Godichon-Baggioni, A. (2017). Fast Estimation of the Median Covariation Matrix with Application to Online Robust Principal Components Analysis. Test, 26(3), 461-480
Vardi, Y. and Zhang, C.-H. (2000). The multivariate L1-median and associated data depth. Proc. Natl. Acad. Sci. USA, 97(4):1423-1426.
Generate a sample of a Gaussian Mixture Model whose centers are generate randomly on a sphere of a given radius.
rSphereGM( n = 500, d = 5, K = 3, pcont = 0, df = 1, cont = "Student", min = -5, max = 5, radius = 5 )rSphereGM( n = 500, d = 5, K = 3, pcont = 0, df = 1, cont = "Student", min = -5, max = 5, radius = 5 )
n |
Number of points per cluster |
d |
Dimension of the space |
K |
Number of clusters |
pcont |
Proportion of contamination |
df |
Degrees of freedom of the Student contamination |
cont |
Type of contamination: can be "Student" (default) or "Unif" |
min |
Minimum value of the contamination |
max |
Maximum value of the contamination |
radius |
Radius of the sphere on which the centers are generated |
A list containing the sample X and the clustering cluster
n <- 500 K <- 3 pcont <- 0.2 sphereGM <- rSphereGM(n=n,K=K,pcont=pcont)n <- 500 K <- 3 pcont <- 0.2 sphereGM <- rSphereGM(n=n,K=K,pcont=pcont)
Function to generate a sample of a Student mixture model with Student contamination
, where follow a Student distribution with means
and variance-covaraince matrices .
rTMMcontStudent(nk, dfT0, muT0, sigmaT0, delta, dfT1, muT1, sigmaT1)rTMMcontStudent(nk, dfT0, muT0, sigmaT0, delta, dfT1, muT1, sigmaT1)
nk |
Vector of the number of observations in each component, giving the proportions |
dfT0 |
Degrees of freedom of the Student distribution |
muT0 |
Matrix of the means of the Student distribution |
sigmaT0 |
Array of the variances of the Student distribution |
delta |
Proportion of contamination |
dfT1 |
Degrees of freedom of the Student contamination |
muT1 |
Matrix of the means of the Student contamination |
sigmaT1 |
Array of the variances of the Student contamination |
A list containing the sample X, the indicator of contamination C and the latent variable Z, giving the classification
# Dimensions K <- 3; nk <- rep(500, K); d <- 5 # Gaussian parameters muT <- rbind(mu1=rep(0, d), mu2=rep(3, d), mu3=rep(-3, d)) sigmaT <- array(dim=c(K, d, d)) sigmaT[1, , ] <- 2*diag(d); sigmaT[2, , ] <- diag(1:d); sigmaT[3, , ] <- diag(1/(1:d)) # Student contamination fraction <- 0.3 dfT <- 1; # Simulation TMMcontStudent <- rTMMcontStudent(nk=nk, dfT0=dfT, muT0=muT, sigmaT0=sigmaT, delta=fraction, dfT1=dfT, muT1=muT, sigmaT1=sigmaT)# Dimensions K <- 3; nk <- rep(500, K); d <- 5 # Gaussian parameters muT <- rbind(mu1=rep(0, d), mu2=rep(3, d), mu3=rep(-3, d)) sigmaT <- array(dim=c(K, d, d)) sigmaT[1, , ] <- 2*diag(d); sigmaT[2, , ] <- diag(1:d); sigmaT[3, , ] <- diag(1/(1:d)) # Student contamination fraction <- 0.3 dfT <- 1; # Simulation TMMcontStudent <- rTMMcontStudent(nk=nk, dfT0=dfT, muT0=muT, sigmaT0=sigmaT, delta=fraction, dfT1=dfT, muT1=muT, sigmaT1=sigmaT)
Function to generate a sample of a Student mixture model with uniform contamination
, where follow a Student distribution with means
and variance-covaraince matrices .
rTMMcontUniform(nk, dfT, muT, sigmaT, delta, lUnif, uUnif)rTMMcontUniform(nk, dfT, muT, sigmaT, delta, lUnif, uUnif)
nk |
Vector of the number of observations in each component, giving the proportions |
dfT |
Degrees of freedom of the Student distribution |
muT |
Matrix of the means of the Student distribution |
sigmaT |
Array of the variances of the Student distribution |
delta |
Proportion of contamination |
lUnif |
Vector of lower bounds of the uniform contamination |
uUnif |
Vector of uppers bounds of the uniform contamination |
A list containing the sample X, the indicator of contamination C and the latent variable Z, giving the classification
# Dimensions K <- 3; nk <- rep(500, K); d <- 5 # Gaussian parameters muT <- rbind(mu1=rep(0, d), mu2=rep(3, d), mu3=rep(-3, d)) sigmaT <- array(dim=c(K, d, d)) sigmaT[1, , ] <- 2*diag(d); sigmaT[2, , ] <- diag(1:d); sigmaT[3, , ] <- diag(1/(1:d)) # Student contamination fraction <- 0.3 dfT <- 1; lower <- rep(0,d); upper <- rep(1,d) # Simulation TMMcontUniform <- rTMMcontUniform(nk=nk, dfT=dfT, muT=muT, sigmaT=sigmaT, delta=fraction, lUnif=lower, uUnif=upper)# Dimensions K <- 3; nk <- rep(500, K); d <- 5 # Gaussian parameters muT <- rbind(mu1=rep(0, d), mu2=rep(3, d), mu3=rep(-3, d)) sigmaT <- array(dim=c(K, d, d)) sigmaT[1, , ] <- 2*diag(d); sigmaT[2, , ] <- diag(1:d); sigmaT[3, , ] <- diag(1/(1:d)) # Student contamination fraction <- 0.3 dfT <- 1; lower <- rep(0,d); upper <- rep(1,d) # Simulation TMMcontUniform <- rTMMcontUniform(nk=nk, dfT=dfT, muT=muT, sigmaT=sigmaT, delta=fraction, lUnif=lower, uUnif=upper)
Summary of the output of a Robust EM algorithm for Mixture Model for a number of clusters in a range
## S3 method for class 'RMM' summary(object, ...)## S3 method for class 'RMM' summary(object, ...)
object |
Object of class |
... |
Additional arguments affecting the summary produced |
Summary of output of a call to multipleRobustMM function
Compute the median of a matrix X using the Weiszfeld algorithm
WeiszfeldMedian( X, init_median = NULL, weights = NULL, epsilon = 1e-08, nitermax = 100L )WeiszfeldMedian( X, init_median = NULL, weights = NULL, epsilon = 1e-08, nitermax = 100L )
X |
A numerical matrix corresponding to the data of size |
init_median |
Initial value of the median, by default equal to 0 (internally handled) |
weights |
Vector of size |
epsilon |
Stopping criterion: the algorithm stops when the difference between two iterations is less than epsilon, by default 1e-08 |
nitermax |
Maximum number of iterations for the Weiszfeld algorithm, by default 100 |
The estimated median
N <- 1000 p <- 4 X <- matrix(rnorm(N*p),ncol=p) WeiszfeldMedian(X)N <- 1000 p <- 4 X <- matrix(rnorm(N*p),ncol=p) WeiszfeldMedian(X)
Compute the median covariation matrix of a matrix X using the Weiszfeld algorithm
WeiszfeldMedianCovariance( X, median_est = NULL, init_median_cov = NULL, weights = NULL, epsilon = 1e-08, nitermax = 100L )WeiszfeldMedianCovariance( X, median_est = NULL, init_median_cov = NULL, weights = NULL, epsilon = 1e-08, nitermax = 100L )
X |
A numerical matrix corresponding to the data of size |
median_est |
Estimation of the median |
init_median_cov |
Initial value of the median covariation matrix, by default equal to the identity matrix (internally handled) |
weights |
Vector of size $n$ of the weights, by default equal to 1 (internally handled) |
epsilon |
Stopping criterion: the algorithm stops when the difference between two iterations is less than epsilon, by default 1e-08 |
nitermax |
Maximum number of iterations for the Weiszfeld algorithm, by default 100 |
The estimated median covariation matrix
N <- 1000 p <- 4 X <- matrix(rnorm(N*p),ncol=p) med_est <- WeiszfeldMedian(X) WeiszfeldMedianCovariance(X,median_est=med_est)N <- 1000 p <- 4 X <- matrix(rnorm(N*p),ncol=p) med_est <- WeiszfeldMedian(X) WeiszfeldMedianCovariance(X,median_est=med_est)
Robust PCA using Weiszfeld algorithm for the median and the median covariation computation
WeiszfeldRobustPCA( X, init_median = rep(0, ncol(X)), init_median_cov = (diag(ncol(X))), weights = rep(1, nrow(X)), scores = 2, epsilon = 1e-08, nitermax = 100 )WeiszfeldRobustPCA( X, init_median = rep(0, ncol(X)), init_median_cov = (diag(ncol(X))), weights = rep(1, nrow(X)), scores = 2, epsilon = 1e-08, nitermax = 100 )
X |
Matrix of size N*p corresponding to the data. The rows are the observations. |
init_median |
Initial value of the median, by default equal to 0 |
init_median_cov |
Initial value of the median covariation matrix, by default equal to the identity matrix |
weights |
Vector of size N of the weights, by default equal to 1 |
scores |
Number of scores to compute, by default 2 |
epsilon |
Stopping criterion: the algorithm stops when the difference between two iterations is less than epsilon, by default 1e-08 |
nitermax |
Maximum number of iterations for the Weiszfeld algorithm, by default 100 |
A list containing :
median : the estimated median
covmedian : the estimated median covariation matrix
scores : the scores
vectors: the eigen vectors
N <- 1000 p <- 4 X <- matrix(rnorm(N*p),ncol=p) WeiszfeldRobustPCA(X)N <- 1000 p <- 4 X <- matrix(rnorm(N*p),ncol=p) WeiszfeldRobustPCA(X)