distance_depth_function: Geenens & Nieto-Reyes functional distance-based depth

Description Usage Arguments Details Value Examples

View source: R/distance-depth.R

Description

Calculates a global distance-based depth vector using a distance matrix. Specifically we use Geenens & Nieto-Reyes's global distance-based depth defined as:

Usage

1
2
3
4
5
6
7
distance_depth_function(x, x_new = NULL, df_out = "auto")

## S3 method for class 'matrix'
distance_depth_function(x, x_new = NULL, df_out = F)

## S3 method for class 'tidy_dist_mat'
distance_depth_function(x, x_new = NULL, df_out = T)

Arguments

x

a n x n square positive symmetric matrix or a tidy_dist_mat

x_new

a n_new x n matrix or tidy_dist_mat where the rows correspond to new observations, the columns correspond to points in x (if x and x_new are matrices then they need to be corrected ordered). If this value is not NULL (default is NULL) then the depth vector will be calculated for these observations relative to observations defined with x and x_new's columns.

df_out

indicates if one should return a data.frame our a vector, by default returns data.frame if dist_mat is a tidy_dist_mat, and a vector if dist_mat is a matrix.

Details

DD(x, \hat{P}) = 1/(n choose 2) \cdot ∑_{i!=j} I(d(X_i, X_j) > max(d(X_i,x), d(X_j,x)))

This function (renamed as depth_function) is shared with TCpredictionbands on github: TCpredictionbands.

Value

depth vector length n with depth values associated with indices in dist_mat or a data.frame with a column called depth

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
dist_mat <- matrix(c(0,   1, 1.5,
                     1,   0, 2,
                     1.5, 2, 0   ),
                   nrow = 3,
                   byrow = TRUE)

dd_vec <- distance_depth_function(dist_mat) # c(1,0,0)

tidy_dm <- tidy_dist_mat(dist_mat)
dd_df <- distance_depth_function(tidy_dm) # depth = c(1,0,0)

skgallagher/timeternR documentation built on Sept. 16, 2021, 7:21 p.m.