trmean: Classical-like depth-based trimmed mean

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/trmean.R

Description

Computes a sample trimmed mean based on the Tukey depth, the Liu depth or the Oja depth.

Usage

1
2
3
trmean(x, alpha, W = function(dep, alpha){return(1)}, 
   method = "Tukey", ndir = 1000, approx = FALSE, 
   eps = 1e-8, ...)

Arguments

x

The data as a matrix, data frame or list. If it is a matrix or data frame, then each row is viewed as one bivariate observation. If it is a list, all components must be numerical vectors of equal length (coordinates of observations).

alpha

Outer trimming fraction (0 to 0.5). Observations whose depth is less than alpha to be trimmed.

W

Nonnegative weight function defined on [0, 1] through its argument dep. Number of arguments can be greater than 2 but the trimming fraction has to be one argument. See examples.

method

Character string which determines the depth function used. method can be "Tukey" (the default), "Liu" or "Oja".

ndir

Positive integer. Number of random directions used when approximate Tukey depth is utilised. Used jointly with approx = TRUE.

approx

Logical. If dimension is 3, should approximate Tukey depth be used? Useful when sample size is large.

eps

Error tolerance to control the calculation.

...

Any additional arguments to the weight function.

Details

Dimension 2 or higher when method is "Tukey" or "Oja"; dimension 2 only when method is "Liu". Exactness of calculation depends on method. See depth.

Value

Multivariate depth-based trimmed mean

Author(s)

Jean-Claude Masse and Jean-Francois Plante, based on Fortran code by Ruts and Rousseeuw from University of Antwerp.

References

Masse, J.C and Plante, J.F. (2003), A Monte Carlo study of the accuracy and robustness of ten bivariate location estimators, Comput. Statist. Data Anal., 42, 1–26.

Masse, J.C. (2008), Multivariate Trimmed means based on the Tukey depth, J. Statist. Plann. Inference, in press.

Rousseeuw, P.J. and Ruts, I. (1996), Algorithm AS 307: Bivariate location depth, Appl. Stat.-J. Roy. St. C, 45, 516–526.

See Also

med for medians and ctrmean for a centroid trimmed mean.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
## exact trimmed mean with default constant weight function
data(starsCYG, package = "robustbase")
trmean(starsCYG, .1)

## another example with default constant weight function
set.seed(159); library(MASS)
mu1 <- c(0,0); mu2 <- c(6,0); sigma <- matrix(c(1,0,0,1), nc = 2)
mixbivnorm <- rbind(mvrnorm(80, mu1, sigma), mvrnorm(20, mu2, sigma))
trmean(mixbivnorm, 0.3)

## trimmed mean with a non constant weight function
W1 <-function(x,alpha,epsilon) {
  (2*(x-alpha)^2/epsilon^2)*(alpha<=x)*(x<alpha+epsilon/2)+
  (-2*(x-alpha)^2/epsilon^2+4*(x-alpha)/epsilon-1)*
  (alpha+epsilon/2<=x)*(x<alpha+epsilon)+(alpha+epsilon<=x)
}
set.seed(345)
x <- matrix(rnorm(210), nc = 3)
trmean(x, .1, W = W1, epsilon = .05)

## two other examples of weighted trimmed mean
set.seed(345)
x <- matrix(rnorm(210), nc = 3)
W2 <- function(x, alpha) {x^(.25)}
trmean(x, .1, W = W2)
W3 <- function(x, alpha, beta){1-sqrt(x)+x^2/beta}
trmean(x, .1, W = W3, beta = 1)

Example output

Loading required package: abind
Loading required package: circular

Attaching package: 'circular'

The following objects are masked from 'package:stats':

    sd, var

Loading required package: rgl
Warning messages:
1: In rgl.init(initValue, onlyNULL) : RGL: unable to open X11 display
2: 'rgl_init' failed, running with rgl.useNULL = TRUE 
3: .onUnload failed in unloadNamespace() for 'rgl', details:
  call: fun(...)
  error: object 'rgl_quit' not found 
   log.Te log.light 
 4.382308  5.003462 
[1]  0.6771635 -0.1432197
[1] -0.14510312 -0.26821761  0.01180318
[1] -0.11907734 -0.17408127 -0.02513136
[1] -0.10808467 -0.15397761 -0.03975651

depth documentation built on Nov. 21, 2019, 5:06 p.m.