R/OutlierStatistic.R

Defines functions OutlierStatistic

Documented in OutlierStatistic

OutlierStatistic <-
function( x, nproj=1000, prior=NULL, seed=NULL) {

   x <- as.matrix(x)
   n <- nrow(x)
   p <- ncol(x)

# don't reset the seed unless multivariate ...

   if (p == 1) nproj <- 1 else if (!is.null(seed)) set.seed(seed)

   if (is.null(prior)) prior <- rep(-Inf,n)

   stat <- apply( apply( x %*% matrix( rnorm(nproj*p), p, nproj), 2, 
       function(vTx) {
                      MED <- median(vTx)
                      MAD <- median(abs(vTx - MED))
                      if (!MAD) return(rep(Inf,n)) else abs(vTx - MED)/MAD
               }), 1, max)

  pmax(stat,prior)
}

Try the probout package in your browser

Any scripts or data that you put into this service are public.

probout documentation built on Feb. 11, 2022, 5:10 p.m.