plot.ssMRCD: Plot Method for ssMRCD Object

View source: R/ssMRCD_methods.R

plot.ssMRCDR Documentation

Plot Method for ssMRCD Object

Description

Produces diagnostic plots for an object of class "ssMRCD" including convergence behavior and visualizations of the covariance matrices.

Usage

## S3 method for class 'ssMRCD'
plot(
  x,
  type = c("convergence", "ellipses", "ellipses_geo"),
  variables = NULL,
  geo_centers = NULL,
  manual_rescale = 1,
  tolerance = 0.95,
  ...
)

Arguments

x

An object of class "ssMRCD".

type

Character string or vector specifying the type of plot(s) to produce. Available options are "convergence", "ellipses", and "ellipses_geo". See Details.

variables

A character vector of length 2 specifying the variable names (columns of the data) used to compute and plot the covariance ellipses.

geo_centers

A matrix specifying the spatial/geographical coordinates of the group centers. Required when type = "ellipses_geo".

manual_rescale

Numeric scaling factor to adjust the size of ellipses in "ellipses_geo" plots.

tolerance

Numeric value (between 0 and 1) specifying the quantile used to define tolerance ellipses. Default is 0.95.

...

Further arguments passed to plotting functions.

Details

type = "convergence": Displays the convergence behavior of the objective function across C-step iterations for each initialization. Red lines indicate non-monotonic convergence.

type = "ellipses": Shows Mahalanobis tolerance ellipses for each group based on their estimated covariance matrix. Only the two variables specified in variables are visualized. The global MCD ellipse may be shown for comparison (if included elsewhere).

type = "ellipses_geo": Projects group-wise covariance ellipses onto a geographical coordinate system (e.g., spatial map), using the positions given in geo_centers. The ellipses are scaled using manual_rescale and drawn using the same two variables as for type = "ellipses".

Value

A named list of ggplot2 plot objects:

plot_convergence

Plot showing convergence diagnostics (if "convergence" selected).

plot_ellipses

Plot of covariance ellipses in variable space (if "ellipses" selected).

plot_geoellipses

Plot of covariance ellipses in geographical space (if "ellipses_geo" selected).

See Also

ssMRCD, locOuts, plot.locOuts

Examples

set.seed(1)
data <- matrix(rnorm(2000), ncol = 4)
colnames(data) <- paste0("V", 1:4)
coords <- matrix(rnorm(1000), ncol = 2)
groups <- sample(1:10, 500, replace = TRUE)
lambda <- 0.3

outs <- locOuts(data = data,
                              coords = coords,
                              groups = groups,
                              lambda = lambda,
                              k = 10)

# Plot convergence
plot(x = outs$ssMRCD, type = "convergence")

# Plot ellipses in variable space
plot(x = outs$ssMRCD, type = "ellipses", variables = c("V1", "V2"))

# Plot ellipses in geographical space
centers <- matrix(rnorm(20), ncol = 2)  # example centers for 10 groups
plot(x = outs$ssMRCD, type = "ellipses_geo", geo_centers = centers, variables = c("V1", "V2"))


ssMRCD documentation built on Nov. 5, 2025, 7:44 p.m.