https://github.com/cran/robCompositions
Raw File
Tip revision: 165037e6629b3969bb2024b9b74bc0bc78b6e1c4 authored by Matthias Templ on 27 February 2013, 00:00:00 UTC
version 1.6.3
Tip revision: 165037e
cenLR.R
cenLR <- function(x){
	#if(dim(x)[2] < 2) stop("data must be of dimension greater equal 2")
	if(dim(x)[2] == 1){
		res <- list(x.clr=x, gm=rep(1,dim(x)[1]))	    	
	} else{
		geometricmean <- function (x) {
			if (any(na.omit(x == 0)))
				0
			else exp(mean(log(unclass(x)[is.finite(x) & x > 0])))
		}
		gm <- apply(x, 1, geometricmean)
		x.clr <- log(x/gm)
		res <- list(x.clr=x.clr, 
				gm=gm
		)
	}
	class(res) <- "clr"
	return(res)  
}
back to top