View source: R/ssMRCD_methods.R
| plot.ssMRCD | R Documentation |
Produces diagnostic plots for an object of class "ssMRCD" including convergence behavior and visualizations of the covariance matrices.
## S3 method for class 'ssMRCD'
plot(
x,
type = c("convergence", "ellipses", "ellipses_geo"),
variables = NULL,
geo_centers = NULL,
manual_rescale = 1,
tolerance = 0.95,
...
)
x |
An object of class |
type |
Character string or vector specifying the type of plot(s) to produce. Available options are |
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 |
manual_rescale |
Numeric scaling factor to adjust the size of ellipses in |
tolerance |
Numeric value (between 0 and 1) specifying the quantile used to define tolerance ellipses. Default is |
... |
Further arguments passed to plotting functions. |
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".
A named list of ggplot2 plot objects:
plot_convergence |
Plot showing convergence diagnostics (if |
plot_ellipses |
Plot of covariance ellipses in variable space (if |
plot_geoellipses |
Plot of covariance ellipses in geographical space (if |
ssMRCD,
locOuts,
plot.locOuts
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"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.