File: gini.R

package info (click to toggle)
r-bioc-edger 3.40.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,484 kB
  • sloc: cpp: 1,425; ansic: 1,109; sh: 21; makefile: 5
file content (15 lines) | stat: -rw-r--r-- 372 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
gini <- function(x)
#	Gini diversity index for columns of a numeric matrix
#	Gordon Smyth
#	Created 5 Feb 2016. Last revised 17 April 2017.
{
	x <- as.matrix(x)
	d <- dim(x)
	for (j in 1:d[2]) x[,j] <- sort.int(x[,j],na.last=TRUE)
	i <- 1:d[1]
	m <- 0.75*d[1]
	S1 <- colSums((i-m)*x , na.rm=TRUE)
	S2 <- colSums(x, na.rm=TRUE)
	(2*(S1/S2+m)-d[1]-1)/d[1]
}