https://github.com/cran/robCompositions
Tip revision: e11c86d2552011aab02cc433769f449e3fd7ce93 authored by Matthias Templ on 06 April 2010, 14:00:48 UTC
version 1.4.0
version 1.4.0
Tip revision: e11c86d
outCoDa.R
outCoDa <- function(x, alpha=0.05, method="robust", h=1/2){
if(dim(x)[2] < 2) stop("need data with at least 2 variables")
covEst <- function(x, type) {
standard <- function(x){
list(mean=colMeans(x, na.rm=TRUE), varmat=cov(x))
}
robust <- function(x){
v <- covMcd(x)
list(mean=v$center, varmat=v$cov)
}
switch(type,
standard = standard(x),
robust = robust(x))
}
z <- ilr(x)
cv <- covEst(z, method)
dM <- sqrt(mahalanobis(z, center=cv$mean, cov=cv$varmat))
limit <- sqrt(qchisq(p=1-alpha, df=ncol(x)-1))
res <- list(mahalDist = dM, limit = limit,
outlierIndex = dM > limit)
class(res) <- "outCoDa"
invisible(res)
}