Plot2dMedian: Plot Two-dimensional Medians

View source: R/Plot2dMedian.R

Plot2dMedianR Documentation

Plot Two-dimensional Medians

Description

This function plots various multivariate medians in the two-dimensional case. The grey dots presented in the figure are the data points and the Spatial, Component-wise (CWmed), Tukey's, Liu's, Projection median as well as the mean value of the data set are plotted in the figure. Oja's median is no longer used, as the package used to produce this function has been archived

Usage

Plot2dMedian(data, xvec, yvec, yamm.nprojs = 2000,
             PmedMCInt.nprojs = 20000, 
             no.subinterval = 36, opt.method = "BFGS", 
             xlab = "Component1", ylab = "Component2")

Arguments

data

The data as a matrix or data frame, with each row being viewed as one multivariate observation.

xvec

A numeric vector containing the maximum and minimum values you desire for the x-axis.

yvec

A numeric vector containing the maximum and minimum values you desire for the y-axis.

yamm.nprojs

The number of projections for the dataset when computing yamm. The default value is 2000.

PmedMCInt.nprojs

The number of projections for the dataset when computing PmedMCInt. The default value is 20000, since PmedMCInt requires large number of projections while doing the Monte Carlo integration to ensure accuracy.

no.subinterval

The number of subintervals while using the trapezoidal rule to approximate the projection median with PmedTrapz function. The default value is 36, and small values (e.g. less than 10) of no.subinterval should not be used, to safeguard accuracy.

opt.method

The method chosen for the optimiser when computing the yamm, with default function “BFGS”. optim is used to minimise the objective function yamm.obj. Apart from “BFGS”, other functions in optim like “Nelder-Mead”, “CG”, “L-BFGS-B”, and “SANN” can also be used.

xlab

Title for x-axis. Must be a character string.

ylab

Title for y-axis. Must be a character string.

Details

The Spatial median is obtained using L1median in the Rpackage robustX. The Component-wise (CWmed), Liu's and Tukey's median are produced using function med in the Rpackage depth. Oja's median is NO LONGER produced using function ojaMedian in the Rpackage OjaNP, as this package has been archived. When computing the projection median, three approximations are implemented and diplayed in the plot, where PmedMCInt uses Monte Carlo method, PmedTrapz is computed by the trapezoidal rule, and yamm uses an optimiser.

The argument xvec and yvec are useful when there are outliers in the data set, which are not expected to be shown in the figure in some cases. Determining the x-axis and y-axis allows you to zoom in the plot and see the difference between multivariate medians and mean value.

References

Chen, F. and Nason, Guy P. (2020) A new method for computing the projection medi an, its influence curve and techniques for the production of projected quantile plots. PLOS One, doi: 10.1371/journal.pone.0229845

See Also

PmedTrapz, PmedMCInt, yamm, yamm.obj, optim.

Examples

# Load a data frame with 103 rows and 2 columns.
# The last two rows of the data are the outliers.
data(clusters2d)
#
# Remove the outliers of the dataset.
cluster_without_outlier <- clusters2d[c(1:101),]
myxvec <- c(min(cluster_without_outlier[,1]), 
          max(cluster_without_outlier[,1]))
myyvec <- c(min(cluster_without_outlier[,2]), 
          max(cluster_without_outlier[,2]))
#
# Plot the figure.
set.seed(5)
Plot2dMedian(clusters2d, myxvec, myyvec, yamm.nprojs = 2000,
             PmedMCInt.nprojs = 20000, no.subinterval = 36, 
             opt.method = "BFGS", xlab = "Component1", 
             ylab = "Component2")

Yamm documentation built on May 20, 2022, 5:06 p.m.