https://github.com/cran/robCompositions
Raw File
Tip revision: b075661d51a7a1ee9b00d94017b8a6be03730ba4 authored by Matthias Templ on 29 April 2009, 00:00:00 UTC
version 1.2.2
Tip revision: b075661
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)
}
back to top