Learn R Programming

MVN (version 6.1)

multivariate_diagnostic_plot: Plot Multivariate Normal Diagnostics and Bivariate Kernel Density

Description

Generates either a Mahalanobis Q-Q plot, an interactive 3D kernel density surface plot, or a 2D kernel density contour plot for exactly two numeric variables. The function is intended for assessing multivariate normality or exploring the bivariate distribution of the input data.

Usage

multivariate_diagnostic_plot(
  data,
  type = c("qq", "persp", "contour"),
  tol = 1e-25,
  use_population = TRUE
)

Value

If type = "qq", returns a ggplot2 object representing a Mahalanobis Q-Q plot. If type = "persp" or "contour", returns an interactive plotly widget displaying the KDE surface or contour, respectively.

Arguments

data

A numeric vector, matrix, or data frame. Non-numeric columns are dropped with a warning; incomplete rows are removed. The input must contain exactly two numeric variables.

type

Character string specifying the type of plot to generate. Must be one of "qq" (Mahalanobis Q-Q plot), "persp" (3D KDE surface), or "contour" (2D KDE contour). Default is "qq".

tol

Numeric tolerance for matrix inversion passed to solve(). Default is 1e-25.

use_population

Logical; if TRUE, uses the population covariance estimator \(\frac{n-1}{n} \times \Sigma\); otherwise uses the sample covariance. Default is TRUE.

Examples

Run this code
if (FALSE) {
library(MASS)
data(iris)

# Mahalanobis Q-Q plot
multivariate_diagnostic_plot(iris[, 1:2], type = "qq")

# 3D KDE surface
multivariate_diagnostic_plot(iris[, 1:2], type = "persp")

# 2D KDE contour
multivariate_diagnostic_plot(iris[, 1:2], type = "contour")
}

Run the code above in your browser using DataLab