# Plot2dMedian: Plot Two-dimensional Medians In Yamm: Multivariate Methods Based on Projections and Related Concepts

## 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, Oja's, Liu's, Projection median as well as the mean value of the data set are plotted in the figure.

## Usage

 ```1 2 3 4``` ```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 pacPP. The Component-wise (CWmed), Liu's and Tukey's median are produced using function `med` in the Rpackage depth. Oja's median is produced using function `ojaMedian` in the Rpackage `OjaNP`. 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, (to appear)

`PmedTrapz`, `PmedMCInt`, `yamm`, `yamm.obj`, `optim`.
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17``` ```# 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") ```