R/eds1.R

Defines functions eds1

Documented in eds1

eds1 <- function(x, q=1, retq = TRUE) {
	bsums <- function(x) {
		if (all(x==0)) return(0)
		sum(-x*log(x),na.rm=TRUE)
	}
	x[x!=0] <- x[x!=0]^q
	if (!is.null(dim(x))) a <- apply(x,1,eds1,retq=retq)
	else {
		x <- matrix(x,nrow=1)
		rs <- sum(x)
		if (rs==0) stop("Zero data")
		x <- x/rs
		a <- bsums(x)
		if (retq) {
			a <- exp(a)
		}
	}
	a
}

Try the MDM package in your browser

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

MDM documentation built on May 30, 2017, 4:58 a.m.