msplot: Outlier Detection using Magnitude-Shape Plot (MS-Plot) based...

View source: R/msplot.R

msplotR Documentation

Outlier Detection using Magnitude-Shape Plot (MS-Plot) based on the directional outlyingness for functional data.

Description

This function finds outliers in univariate and multivariate functional data using the MS-Plot method described in Dai and Genton (2018) \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1080/10618600.2018.1473781")}. Indices of observations flagged as outliers are returned. In addition, the scatter plot of VO against MO (||MO||) can be requested for univariate (multivariate) functional data.

Usage

msplot(
  dts,
  data_depth = c("random_projections"),
  n_projections = 200,
  seed = NULL,
  return_mvdir = TRUE,
  plot = TRUE,
  plot_title = "Magnitude Shape Plot",
  title_cex = 1.5,
  show_legend = T,
  ylabel = "VO",
  xlabel
)

Arguments

dts

A matrix/data frame for univariate functional data (of size n observations by p domain points) or a 3-dimensional array for multivariate functional data (of size n observations by p domain points by d dimension).

data_depth

The depth used in the computation of the directional outlyingness of dts. The projection depth is always used. Support for other depth methods will be added.

n_projections

The number of random directions to generate for computing the random projection depth. By default 200 directions are generated.

seed

An integer indicating the seed to set when generating random directions for computing the random projection depth. NULL by default in which case no seed is set.

return_mvdir

A logical value indicating whether to return the mean and variation of directional outlyingness (MO and VO). For univariate functional data, MO and VO are vectors. For multivariate functional data, VO is a vector while MO is a matrix of size n x d.

plot

A logical indicating whether to make the msplot of VO against MO. In the case of multivariate functional data, a plot of VO against ||MO|| is made.

plot_title

The title of the plot. Set to "Magnitude Shape Plot" by default. Ignored if plot = FALSE.

title_cex

Numerical value indicating the size of the plot title relative to the device default. Set to 1.5 by default. Ignored if plot = FALSE.

show_legend

A logical indicating whether to add legend to plot if plot = TRUE.

ylabel

The label of the y-axis. Set to "VO" by default.

xlabel

The label of the x-axis if plot = TRUE. If not specified (default), set to "MO" for univariate functional data and "||MO||" for multivariate functional data.

Details

MS-Plot finds outliers by computing the mean and variation of directional outlyingness (MO and VO) described in Dai and Genton (2019) \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1016/j.csda.2018.03.017")}. A multivariate data whose columns are the computed MO and VO is then constructed and the robust mahalanobis distance(s) of the rows of this matrix are computed (using the minimum covariate determinant estimate of the location and scatter). The tail of the distribution of these distances is approximated using the F distribution according to Hardin and Rocke (2005) \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1198/106186005X77685")} to get the cutoff. The projection depth is always used for computing the directional outlyingness (as suggested by Dai and Genton (2019) \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1016/j.csda.2018.03.017")}).

Value

Returns a list containing:

outliers_index

an integer vector containing the indices of the outliers.

median_curve

the index of the median function (which is the function with the smallest robust mahalanobis distance computed from the matrix whose columns are made up of MO and VO).

mean_outlyingness

if return_mvdir = TRUE, a numeric vector of the mean of directional outlyingness for univariate functional data or an n x d matrix of the mean of directional outlyingness for multivariate functional data.

var_outlyingness

if return_mvdir = TRUE, a numeric vector of length n observations containing the variation of directional outlyingness.

Author(s)

Oluwasegun Taiwo Ojo.

References

Dai, W., and Genton, M. G. (2018). Multivariate functional data visualization and outlier detection. Journal of Computational and Graphical Statistics, 27(4), 923-934.

Dai, W., and Genton, M. G. (2019). Directional outlyingness for multivariate functional data. Computational Statistics & Data Analysis, 131, 50-65.

Hardin, J., and Rocke, D. M. (2005). The distribution of robust distances. Journal of Computational and Graphical Statistics, 14(4), 928-946.

See Also

dir_out for directional outlyingness and projection_depth for multivariate projection depth.

Examples

# Univariate magnitude model in Dai and Genton (2018).
dt1 <- simulation_model1()
msplot_object <- msplot(dts = dt1$data)
msplot_object$outliers_index
msplot_object$mean_outlyingness
msplot_object$var_outlyingness


fdaoutlier documentation built on Oct. 1, 2023, 1:06 a.m.